C   116

wait.c

Guest on 4th September 2021 05:40:35 AM

  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. int main(void) {
  7.    int child_status, pid, pidwait;
  8.    if ((pid = fork()) == 0) {
  9.       printf("This is the child!\n");
  10.       sleep(4);
  11.       exit(1);
  12.    }
  13.    else {
  14.       pidwait = wait(&child_status);
  15.       printf("child %d has terminated status %d \n", pidwait, child_status);
  16.    }
  17.    exit(0);
  18. }

Raw Paste


Login or Register to edit or fork this paste. It's free.