/********************************************************************** * forkTest.c --- a simple test of whether or not the OS automatically * terminates descendants of a terminated process. **********************************************************************/ #include #include #include #include int main(void) { pid_t pid; printf("Parent running.\n"); if ((pid = fork()) == -1) { printf("Parent couldn't procreate.\n"); exit(1); } else if (pid == 0) /* The child. */ { printf("Child running.\n"); /* Sleep for 5 seconds. This ought to be long enough for the parent to have terminated. */ sleep(5); printf("Child still running.\n"); printf("Child exiting.\n"); } else /* The parent. */ { printf("Child pid is %d.\n", pid); printf("Parent exiting.\n"); } exit(0); }