// waitpid_ex.c // October 28, 2000 // Program to illustrate waitpid system call #include #include #include int main() { pid_t pid; int status; // Create a child process if ((pid = fork()) < 0) { perror("fork"); exit(1); } // end if if (pid == 0) { printf("Child process created\n"); exit(15); } // end if else { // Parent process waitpid(pid, &status, WUNTRACED); } // end else if (WIFEXITED(status)) printf("PID %d exits: %d\n", pid, WEXITSTATUS(status)); else if (WIFSTOPPED(status)) printf("PID %d stopped by: %d\n", pid, WSTOPSIG(status)); else if (WIFSIGNALED(status)) printf("PID %d killed by: %d\n", pid, WTERMSIG(status)); else perror("Waitpid"); exit(0); } // end main