/*--------------------------------------------------------------------*/ /* testfork.c */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #include #include #include #include /*--------------------------------------------------------------------*/ /* Demonstrate the system-level fork() function and the standard C 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 iPid; int iRet; printf("%d parent\n", (int)getpid()); iRet = fflush(stdin); if (iRet == EOF) {perror(argv[0]); exit(EXIT_FAILURE); } iRet = fflush(stdout); if (iRet == EOF) {perror(argv[0]); exit(EXIT_FAILURE); } iPid = fork(); if (iPid == -1) {perror(argv[0]); exit(EXIT_FAILURE); } printf("%d parent and child\n", (int)getpid()); return 0; } /*--------------------------------------------------------------------*/ /* Sample executions: $ gcc217 testfork.c -o testfork $ ./testfork 29285 parent 29285 parent and child 29286 parent and child $ ./testfork 29287 parent 29287 parent and child 29288 parent and child */