/* # gdb101 ./forktest ... (gdb) catch fork Catchpoint 1 (fork) (gdb) r Starting program: /mnt/forktest/forktest Catchpoint 1 (forked process 830), _fork () at _fork.S:4 4 _fork.S: No such file or directory. (gdb) kill Kill the program being debugged? (y or n) y [Inferior 1 (process 828) killed] (gdb) quit */ #include #include #include #include #include #include int main(void) { pid_t pid, wpid; pid = fork(); if (pid == -1) err(1, "fork"); if (pid == 0) { printf("I'm in the child\n"); exit(1); } printf("I'm in the parent\n"); wpid = waitpid(pid, NULL, 0); if (wpid < 0) err(1, "waitpid"); return (0); }