pastebin - collaborative debugging tool
513.kpaste.net RSS

Difference between
modified post b9e by Anonymous on Fri 14th Oct 2011 09:04
original post 77a14 by Anonymous on Fri 14th Oct 2011 04:11
Download diff
Show old version | new version | both versions

    
11
/* CODE WILL TAKE A COMMAND, PASS IT TO CREATEPROCESS(),
22
 * FORK A CHILD AND EXECUTE COMMAND
33
 *
44
 *
55
 */
66
77
#include <unistd.h>
88
#include <sys/types.h>
99
#include <stdio.h>
1010
#include <stdlib.h>
1111
1212
char* buffer;
1313
pid_t pid;
1414
1515
void startProcess( char* );
1616
1717
int main ()
1818
{
1919
	char* input = (char*)malloc( 128 );
2020
	buffer = NULL;
2121
2222
	while( 1 )
2323
	{
2424
		printf( "EECE315_Shell - %s$ ", getcwd(NULL, 0) );
2525
		gets( input );
2626
		if( strcmp(input, "exit") == 0 )
2727
		{
2828
			printf( "Terminating shell...\n" );
2929
			return 0;
3030
		}
3131
		else if( strcmp(input, "") != 0 )
3232
		{
3333
			startProcess( input );
3434
		}
3535
	}
3636
}
3737
3838
void startProcess( char* input )
3939
{
4040
	pid = fork();
4141
4242
	if( pid == 0 )
4343
	{
4444
		execvp( input, NULL );
4545
	}
4646
	else if( pid > 0 )
4747
	{
4848
		//parent wait
4949
	}
5050
	else
5151
	{
5252
		printf( "Fork returned error code, no child" );
5353
	}
5454
}
5555

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at