/*-------------------------------------------------------------------*/ /* testforkret.c */ /* The fork system call's return value. */ /*-------------------------------------------------------------------*/ #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); } else { printf("Parent process (%ld)\n", (long)getpid()); fflush(stdout); } printf("Parent and child process (%ld)\n", (long)getpid()); fflush(stdout); return 0; } /* Sample executions: $ gcc -o testforkret testforkret.c $ testforkret Parent process (262) Parent process (262) Parent and child process (262) Child process (264) Parent and child process (264) $ testforkret Parent process (287) Parent process (287) Parent and child process (287) Child process (288) Parent and child process (288) $ */