pastebin - collaborative debugging tool
513.kpaste.net RSS


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)

  1. /* CODE WILL TAKE A COMMAND, PASS IT TO CREATEPROCESS(),
  2.  * FORK A CHILD AND EXECUTE COMMAND
  3.  *
  4.  *
  5.  */
  6.  
  7. #include <unistd.h>
  8. #include <sys/types.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. char* buffer;
  13. pid_t pid;
  14.  
  15. void startProcess( char* );
  16.  
  17. int main ()
  18. {
  19.         char* input = (char*)malloc( 128 );
  20.         buffer = NULL;
  21.  
  22.         while( 1 )
  23.         {
  24.                 printf( "EECE315_Shell - %s$ ", getcwd(NULL, 0) );
  25.                 gets( input );
  26.                 if( strcmp(input, "exit") == 0 )
  27.                 {
  28.                         printf( "Terminating shell...\n" );
  29.                         return 0;
  30.                 }
  31.                 else if( strcmp(input, "") != 0 )
  32.                 {
  33.                         startProcess( input );
  34.                 }
  35.         }
  36. }
  37.  
  38. void startProcess( char* input )
  39. {
  40.         pid = fork();
  41.  
  42.         if( pid == 0 )
  43.         {
  44.                 execvp( input, NULL );
  45.         }
  46.         else if( pid > 0 )
  47.         {
  48.                 //parent wait
  49.         }
  50.         else
  51.         {
  52.                 printf( "Fork returned error code, no child" );
  53.         }
  54. }

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