/* forktest.c Started by Jeff Ondich on 3/26/96 Last modified 3/29/10 This program gives a simple example of fork, and how a process can create a child process. */ #include #include const long limit = 1000000000; const long frequency = 1000000; int main() { long i; if( fork() == 0 ) { /* child */ for( i=0; i < limit; i++ ) { if( i % frequency == 0 ) { printf( "I'm the child: %ld\n", i ); fflush( stdout ); } } } else { /* parent */ for( i=0; i < limit; i++ ) { if( i % frequency == 0 ) { printf( "I'm the parent: %ld\n", i ); fflush( stdout ); } } } return 0; }