/* a simple parent; version1; sys name: parent1.c Now we better create a program, which will replace the replica of the parent. We have named this replacing program child1.c and have made an executable out of it carrying the name child1 (use the -o option). In parent process fork() returns the pid of the child; in the child process fork returns 0. */ #include #define NULL 0 #include #include #include int main(void) { int pidValue = fork(); if (pidValue > 0) { /* Parent code here */ printf("Process[%d]: Parent in execution ... \n", getpid()); sleep(2); if (wait(NULL) > 0) { /* Child terminating */ printf("Process[%d]: Parent detects terminating child \n", getpid()); } printf("Process[%d]: Parent terminating ... \n", getpid()); } else { if (pidValue == 0) { /* this is the child's process */ execve("child1", NULL, NULL); exit(0); /* should never get here, terminate */ } else { /* should never get here; things such as not enought mem */ exit(0); } } return(0); }