SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8.  
  9. int main(int argc, char *argv[]) //argc = argument count,  argv = argument vector
  10. {
  11.  
  12.     int i;
  13.     for(i = 1; i < argc; i++)
  14.     {
  15.         printf("%dth argument: %s\n", i , argv[i]);
  16.         pid_t child = fork();
  17.             if(child == 0)
  18.         {
  19.             int commandExitStatus = execlp(argv[i], argv[i], NULL);
  20.             if ( commandExitStatus == -1)//Failed
  21.               printf("%d",commandExitStatus);
  22.             else
  23.               printf("Successful");
  24.  
  25.             exit(0);
  26.         }
  27.     }
  28.  
  29.     printf("============= END ===============\n");
  30.  
  31.  
  32.     /* This code runs concurrently
  33.     int i = 10;
  34.     while (i > 0)
  35.     {
  36.         pid_t child = fork();
  37.         if(child == 0) {
  38.         printf("i: %d\n", i--);
  39.         exit(0);
  40.         }
  41.     }
  42.     */
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top