/*------------------------------------------------------------------*/ /* testfork.c */ /* Author: Bob Dondero */ /* The fork system call. */ /*------------------------------------------------------------------*/ #include #include #include #include int main(int argc, char *argv[]) { pid_t iRet; printf("Parent process (%d)\n", (int)getpid()); fflush(NULL); iRet = fork(); if (iRet == -1) {perror(argv[0]); return EXIT_FAILURE; } printf("Parent and child processes (%d)\n", (int)getpid()); return 0; } /*------------------------------------------------------------------*/ /* Sample executions: $ gcc -Wall -ansi -pedantic testfork.c -o testfork $ testfork Parent process (14528) Parent and child processes (14529) Parent and child processes (14528) $ testfork Parent process (14530) Parent and child processes (14531) Parent and child processes (14530) */