//----------------------------------------------------------------- // execdemo.cpp // // This is the program we wrote quickly during class, to show // how an application can fork a child-process which then may // execute another program. Now we have added some comments. // // to compile: $ g++ execdemo.cpp -o execdemo // to execute: $ ./execdemo [...] // // programmer: ALLAN CRUSE // written on: 04 MAR 2009 //----------------------------------------------------------------- #include // for printf() #include // for fork() #include // for exit() #include // for wait() int main( int argc, char *argv[] ) { // parent forks a child-process int retval = fork(); if (retval == 0) { // child-process executes this block execve( argv[1], &argv[1], 0 ); printf( "unknown program -- child is quitting\n" ); exit( 1 ); } // parent-process waits for child-process to exit wait( NULL ); printf( "parent is quitting\n" ); }