/* Fork off one child that exits with a value of 0. The parent uses macros to examine the status variable of wait. */ #include #include #include #include int main() { int i, j, status; i = fork(); if (i > 0) { j = wait(&status); printf("Parent: Child done.\n"); printf(" Return value: %d\n", j); printf(" Status: %d\n", status); printf(" WIFSTOPPED: %d\n", WIFSTOPPED(status)); printf(" WIFSIGNALED: %d\n", WIFSIGNALED(status)); printf(" WIFEXITED: %d\n", WIFEXITED(status)); printf(" WEXITSTATUS: %d\n", WEXITSTATUS(status)); printf(" WTERMSIG: %d\n", WTERMSIG(status)); printf(" WSTOPSIG: %d\n", WSTOPSIG(status)); } else { printf("Child (%d) calling exit(0)\n", getpid()); exit(0); // BTW, "return 0" will do the same thing. } return 0; }