/* This program creates a new process and allows both child and parent 
 * to report their identification numbers.
 *
 * Created by Henry Walker
 */

#include <sys/types.h>       /* file of data types needed for many compilers */
#include <unistd.h>          /* needed for fork, getpid procedures */
#include <stdio.h>

int main (void)
{  pid_t pid;                /* variable to record process id of child */
   
   pid = fork();             /* create new process */
   if ( -1 == pid)           /* check for error in spawning child process */
     { perror ("error in fork");  
       exit (1);
     }

   if (0 == pid)             /* check if this is the new child process */
     { /* processing for child */
       printf ("This output comes from the child process\n");
       printf ("Child report:  my pid = %d\n", getpid());
     } 
  else 
     { /* processing for parent */
       printf ("This output comes from the parent process.\n");
       printf ("Parent report:  my pid = %d   child's pid = %d\n", 
                getpid(), pid);     
     }

   exit (0);                 /* quit by reporting no error */
}
