#include #include #include #include void child_status_changed(int signum){ int status; pid_t waited_pid = wait(&status); printf("We just waited on pid %d which exited with status %d\n", waited_pid, (char)(status >> 8)); } int main(){ int pid = fork(); if(pid == 0) {// Then we are the child printf("We're the child, but we're not going to live very long. Just 10 seconds!.\n"); sleep(10); return 13; } else { struct sigaction our_action; our_action.sa_handler = child_status_changed; sigaction(SIGCHLD, &our_action, 0); printf("We created a child with pid %d\n", pid); printf("We're the parent. It's time for us to sleep :)\n"); // get time // while(time isn't 100 seconds later) sleep(100); // End of loop printf("Done sleeping now\n"); } return 0; }