/*--------------------------------------------------------------------*/ /* testfork.c */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #include #include #include #include /*--------------------------------------------------------------------*/ /* Demonstrate the fork() system call and the fflush() function. Return 0. As usual, argc is the command-line argument count, and argv contains the command-line arguments. */ 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]); exit(EXIT_FAILURE); } printf("Parent and child processes (%d)\n", (int)getpid()); return 0; } /*--------------------------------------------------------------------*/ /* Sample executions: $ gcc217 testfork.c -o testfork $ testfork Parent process (29285) Parent and child processes (29285) Parent and child processes (29286) $ testfork Parent process (29287) Parent and child processes (29287) Parent and child processes (29288) */