Answer to Homework 3 of 3 November 1997 Compile the files by gcc pr.c -o pr.out and gcc ch.c -o ch.out respectively. Then run pr.out * * * * * * * * * /* pr.c */ #include #include #include main() { pid_t my_id; printf( "Parent process starts, PID = %d.\n", getpid()); sleep( 1); if ( (my_id = fork()) == -1) { fprintf( stderr, "Unable to fork a new process.\n"); return 1; } if ( my_id == 0) { char * arg_list[] = { 0}; char * env_list[] = { 0}; printf( "I am the child, with child PID = %d.\n", getpid()); printf( "I will overlay myself with another process.\n"); sleep( 2); execve( "./ch.out", arg_list, env_list); } sleep( 1); printf( "I am still the parent process with PID = %d.\n", getpid()); return 0; } * * * * * * * * * /* ch.c */ #include #include main() { printf( "I overlay the child, but still have PID = %d.\n", getpid()); return 0; } * * * * * * * * * Wim Ruitenburg