/* forkexample.c                      */
/* Example of use of fork system call */
/* To compile me on Solaris or Linux:  gcc -o filename filename.c */

#include <stdio.h>
#define ITERATIONS 10

main()
{
  int pid;
  int i, j;  

  if ( (pid = fork() ) != 0 )
    { /* parent executes here */
      for(i=0;i<ITERATIONS;i++)  
	{ 
	  printf("i= %d; I am the parent. Returned pid is child's: %d\n", i, pid);
	  for(j=0;j<50000;j++);  /* spin on cpu for a little while */
	}
    }
  else
    { /* child executes here */
      for(i=0;i<ITERATIONS;i++)
	{ printf("i=%d; I am the child. Returned pid is '0': %d\n", i, pid);
	  for(j=0;j<50000;j++);  /* spin on cpu for a little while */
	}
    }
}

