/*-------------------------------------------------------------------*/ /* testforkexit.c */ /* Using the exit function to terminate a child process. */ /*-------------------------------------------------------------------*/ #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"); exit(0); } printf("This code is executed in the parent process.\n"); return 0; } /* Sample executions: $ testforkexit This code is executed in the child process. This code is executed in the parent process. $ testforkexit This code is executed in the parent process. This code is executed in the child process. $ */