/*-------------------------------------------------------------------*/ /* testforkexit.c */ /* The fork system call used with the exit function. */ /*-------------------------------------------------------------------*/ #include #include int main(int argc, char *argv[]) { int iPid; printf("Parent process (%ld)\n", (long)getpid()); fflush(stdout); iPid = fork(); if (iPid == -1) { perror(argv[0]); return 1; } if (iPid == 0) { printf("Child process (%ld)\n", (long)getpid()); fflush(stdout); exit(0); } printf("Parent process (%ld)\n", (long)getpid()); fflush(stdout); return 0; } /* Sample executions: --> gcc -Wall -ansi -pedantic -o testforkexit testforkexit.c --> testforkexit Parent process (456) Parent process (456) Child process (457) --> testforkexit Parent process (465) Child process (466) Parent process (465) */