/* Purpose:	create a child process that starts looping, 
		and then terminate it.				 */

#include <iostream> 
using namespace std;

#include <unistd.h>
#include <signal.h>

int main (void) 
{
	int child_pid, i;

	child_pid = fork();
	if (child_pid == 0)
	{	
		/* the child process */

		for (i = 1;  i <= 20000000;  i++)
		{
			if (i % 100 == 0)
			{
				cout << "I'm still alive." << endl;
			}
		}
	}    
	else
	{
		/* the parent process */

		/* wait for one second to guarantee that the 
		   child is executed first */    
		sleep(1);	


		cout << "Dispatching ..." << endl;

		/* send SIGINT to the child process */    
		kill(child_pid, SIGINT);	

		cout << "Dispatched" << endl;
        }
}

