/*-------------------------------------------------------------------*/ /* testfork.c */ /* The fork system call. */ /*-------------------------------------------------------------------*/ #include #include int main(int argc, char *argv[]) { int iRet; printf("Parent process (%ld)\n", (long)getpid()); fflush(NULL); iRet = fork(); if (iRet == -1) {perror(argv[0]); return 1; } printf("Parent and child processes (%ld)\n", (long)getpid()); return 0; } /* Sample executions: $ gcc -Wall -ansi -pedantic -o testfork testfork.c $ testfork Parent process (29101) Parent and child processes (29102) Parent and child processes (29101) $ testfork Parent process (29103) Parent and child processes (29104) Parent and child processes (29103) $ */