25 lines
500 B
C
25 lines
500 B
C
#include <stdio.h>
|
|
#include <unistd.h> // fork, sleep
|
|
#include <stdlib.h> // exit
|
|
#include <sys/wait.h> // wait
|
|
|
|
int main(){
|
|
int status;
|
|
int pid;
|
|
|
|
if ((pid = fork()) == 0) {
|
|
printf("I'm the son and going to sleep for 30s.\n");
|
|
sleep(30);
|
|
exit(3);
|
|
}
|
|
else if (pid == -1) {
|
|
printf("fork() failed");
|
|
exit(2);
|
|
}
|
|
|
|
wait(&status);
|
|
|
|
printf("wait status 0x%x | 0x%x | 0x%x\n", status, (status>>8) & 0xff, status & 0xff);
|
|
return 0;
|
|
}
|