/*-------------------------------------------------------------------*/ /* testforkret.c */ /* Using the return value of the fork system call. */ /*-------------------------------------------------------------------*/ #include #include int main(int argc, char *argv[]) { int iPid; iPid = fork(); if (iPid == -1) { printf("Failed to execute fork.\n"); exit(1); } if (iPid == 0) { printf("This code is executed in the child process.\n"); } else { printf("This code is executed in the parent process.\n"); } printf("This code is executed in both the parent and child process.\n"); return 0; } /* Sample executions: $ testforkret This code is executed in the child process. This code is executed in the parent process. This code is executed in both the parent and child process. This code is executed in both the parent and child process. $ testforkret This code is executed in the parent process. This code is executed in the child process. This code is executed in both the parent and child process. This code is executed in both the parent and child process. $ testforkret This code is executed in the parent process. This code is executed in both the parent and child process. This code is executed in the child process. This code is executed in both the parent and child process. $ */