diff options
Diffstat (limited to 'scraps/forktest.c')
-rw-r--r-- | scraps/forktest.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scraps/forktest.c b/scraps/forktest.c new file mode 100644 index 0000000..40ecb86 --- /dev/null +++ b/scraps/forktest.c @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> + +int main() { + printf("forktest pid: %d\n", getpid()); + fflush(stdout); + pid_t pid = fork(); + if (pid == 0) { + printf("grandchild pid: %d\n", getpid()); + fflush(stdout); + // printf("child ppid: %d\n", getppid()); + execl("./bin/grandchild", "./bin/grandchild", (char*)0); + } + int status; + while (1) { + waitpid(pid, &status, 0); + if(WIFEXITED(status)) { + printf("grandchild exited\n"); + return 0; + } + } +}
\ No newline at end of file |