wait.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <sys/wait.h> 5 #include <sys/types.h> 6 7 int main(int argc, char *argv[]) 8 { 9 pid_t pid; 10 11 if((pid = fork()) == 0) 12 { // child 13 printf("sleeping...\n"); 14 sleep(3); 15 printf("waking ... and exiting\n"); 16 } 17 else if (pid > 0) 18 { // parent 19 printf("waiting for child\n"); 20 wait(NULL); 21 printf("child woke up\n"); 22 } 23 exit(0); 24 } |