//------------------------------------------------------------------ // forkdemo.cpp // // This demo explores the effect of calling 'fork()' in a loop. // // programmer: ALLAN CRUSE // written on: 16 MAY 2005 //------------------------------------------------------------------ #include // for printf() #include // for fork() #include // for wait() int main( int argc, char **argv ) { int i = 0; do { ++i; if ( fork() == 0 ) write( 1, "Hello \n", 8 ); // child-process else wait( NULL ); // parent-process waits till child exits } while ( i < 3 ); }