#include #include #include #include int main(int argc, char **argv) { printf("before fork my pid %d\n", getpid()); pid_t childpid = fork(); if (childpid == -1) perror("fork"), exit(0); if (childpid == 0) { printf("child: my pid %d, my parent's pid is %d\n", getpid(), getppid()); //raise(SIGKILL); //void *n = *(void **)NULL; return 42; } else { for (int i = 0; i < 2; i++) { //printf("parent: my pid %d, my child's pid is %d\n", getpid(), childpid); int status; pid_t childexited = wait(&status); if (childexited == -1) { perror("wait"); continue; } if (WIFEXITED(status)) { printf("parent: my normally exiting child is %d, with %d\n", childexited, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { printf("parent: my crashed or signalled child is %d, with %d\n", childexited, WTERMSIG(status)); } else { printf("something else\n"); } } } }