/* Purpose: show that the child can be set up to ignore a signal from 
	    its parent.							*/

#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 */
		signal(SIGINT, SIG_IGN);

		for (i = 0;  i < 20000000; i++)
		{
			if (i % 1000000 == 0)
			{
				cout << "My process number = " << getpid() << endl;
				cout << "I'm still alive, and i = " << i << endl;
			}
		}
		cout << "All done!  Nobody dared to stop me!" << endl;
	}    
	else
	{
		/* the parent process */

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

		/* send SIGINT to the child process */    
		kill(child_pid, SIGINT);	
		cout << "Parent has sent signal and is terminating" << endl;
        }
}
