Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1.  pid_t pid;
  2.   int status;
  3.   if ((pid = fork())< 0){
  4.    printf("*** ERROR: forking child process failed\n");
  5.            exit(1);
  6.   }
  7.   else if (pid == 0) {          /* for the child process:         */
  8.          if (execvp(*name, name) < 0) {     /* execute the command  */
  9.                printf("*** ERROR: exec failed\n");
  10.                exit(1);
  11.          }
  12.      }
  13.      else {                                  /* for the parent:      */
  14.          while (wait(&status) != pid)       /* wait for completion  */;
  15.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement