/* fork1.c Started by Jeff Ondich on 3/26/96 Last modified 3/26/96 This program gives a simple example of how to create a new process. When run, this one shows multi-tasking in action--you can see the parent and child processes taking turns. */ #include #include /* I've taken to being obsessively careful about over-running arrays. Since I don't allow myself to use strcpy() any more, I need to tell strncpy() how big my array is. It's pretty stupid in this tiny program, but that's obsession for you. */ #define NAME_LENGTH 20 void main() { long i, pid; char processName[NAME_LENGTH]; /* Create the new process. */ pid = fork(); if( pid != 0 ) strncpy( processName, "Parent", NAME_LENGTH ); else strncpy( processName, "Child", NAME_LENGTH ); /* Start counting. */ for( i=0; i < 500000; i++ ) if( i % 25000 == 0 ) { fprintf( stderr, "%s: %d\n", processName, i ); fflush( stderr ); } }