- /* CODE WILL TAKE A COMMAND, PASS IT TO CREATEPROCESS(),
- * FORK A CHILD AND EXECUTE COMMAND
- *
- *
- */
- #include <unistd.h>
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- char* buffer;
- pid_t pid;
- void startProcess( char* );
- int main ()
- {
- char* input = (char*)malloc( 128 );
- buffer = NULL;
- while( 1 )
- {
- printf( "EECE315_Shell - %s$ ", getcwd(NULL, 0) );
- gets( input );
- if( strcmp(input, "exit") == 0 )
- {
- printf( "Terminating shell...\n" );
- return 0;
- }
- else if( strcmp(input, "") != 0 )
- {
- startProcess( input );
- }
- }
- }
- void startProcess( char* input )
- {
- pid = fork();
- if( pid == 0 )
- {
- execvp( input, NULL );
- }
- else if( pid > 0 )
- {
- //parent wait
- }
- else
- {
- printf( "Fork returned error code, no child" );
- }
- }
Untitled
Posted by Anonymous on Fri 14th Oct 2011 09:04
raw | new post
view followups (newest first): UPDATED UPON10/14/09:04PM [BY:VIN] by Anonymous
modification of post by Anonymous (view diff)
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.