23 lines
392 B
C
23 lines
392 B
C
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
int main(){
|
|
int pid = fork();
|
|
if (pid == -1) {
|
|
exit(0);
|
|
}
|
|
if (pid == 0) {
|
|
printf("fork = %d, pid = %d, ppid = %d\n",pid,getpid(),getppid());
|
|
sleep(4);
|
|
exit(2);
|
|
}
|
|
if (pid > 0) {
|
|
printf("fork = %d, pid = %d, ppid = %d\n",pid,getpid(),getppid());
|
|
printf("%d\n",wait());
|
|
exit(2);
|
|
}
|
|
}
|