// This will not run (properly) under MSDOS

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream.h>

int main ()
{
   cout << "In the beginning of the program: PID=" << getpid()
        << " and PPID=" << getppid() << endl;

   pid_t i = fork();

   cout << "Fork returned: " << i << endl;

   /* This is the code for the child */
   
   if (i == 0) {
      cout << "Child process: PID=" << getpid()
           << " and PPID=" << getppid() << endl;
      return 42;
   }

   /* This is the code for the parent */

   else {
      int status;

      cout << "Parent process: PID=" << getpid()
           << " and PPID=" << getppid() << endl;

      /* For descriptions of WIFEXITED and WEXITSTATUS,
         read Chan or see the man page for 'wait' (man 2 wait) */

      wait(&status);

      if (WIFEXITED(status))
         cout << "My child ended with status " << WEXITSTATUS(status) << endl;
      else
         cout << "My child died ungracefully\n";

      return 0;
   }
}
