/*-------------------------------------------------------------------*/ /* testforkexit.c */ /* The fork and _exit system calls. */ /*-------------------------------------------------------------------*/ #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 -o testforkexit testforkexit.c $ testforkexit Parent process (456) Parent process (456) Child process (457) $ testforkexit Parent process (465) Child process (466) Parent process (465) $ */