// forktest.cpp

// This program demonstrates the use of fork(), getpid(), and
// getppid().  These are the basic Unix process creation calls.

// Author: Dr. Jeff Blessing
// Date:   November 23, 2000

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
using namespace std;

int main()
{
   pid_t child_pid;

   cout << "PID: " << getpid() << ", parent: " << getppid() << endl;
   switch (child_pid = fork())
   {
      case (pid_t) -1:	perror("fork failed");
			break;
      case (pid_t)  0:	cout << "Child created. PID: " << getpid()
			     << ", parent: " << getppid() << endl;
			exit(0);
      default:	cout << "Parent after fork(). PID: " << getpid()
		     << ", child PID: " << child_pid << endl;
   }
   return 0;
}
