/* exectest.c Started by Jeff Ondich on 3/26/96 Last modified 4/1/02 This program gives a simple example of exec, and how a parent process can wait for a child process to return. */ #include #include #include #include int main() { int status; pid_t pid; /* Create the new process. */ pid = fork(); if( pid != 0 ) /* Parent */ { printf( "Parent just created child, ID %d\n", pid ); fflush( stdout ); pid = wait( &status ); printf( "My child ID %d just exited with status %d\n", pid, WEXITSTATUS(status) ); fflush( stdout ); } else /* Child */ { printf( "Process %d is about to execute 'getanumber'\n", getpid() ); fflush( stdout ); execlp( "getanumber", "getanumber", NULL ); printf( "Will this get printed? No.\n" ); fflush( stdout ); } return( 0 ); }