blob: 1b5a36cae004b01daea9d9727da0765195e3bc1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
printf("grandchild pid: %d\n", getpid());
fflush(stdout);
pid_t pid = fork();
if (pid == 0) {
printf("great-grandchild pid: %d\n", getpid());
fflush(stdout);
// printf("child ppid: %d\n", getppid());
execl("/bin/ls", "/bin/ls", (char*)0);
}
int status;
while (1) {
waitpid(pid, &status, 0);
if(WIFEXITED(status)) {
printf("great-grandchild exited\n");
return 0;
}
}
}
|