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

int main(void)
{
	int i;
	void signal_catcher(int);

	if (signal(SIGINT, signal_catcher)==SIG_ERR)
	{
		perror("SIGINT");
		exit(1);
	}

	if (signal(SIGQUIT, signal_catcher)==SIG_ERR)
	{
		perror("SIGQUIT");
		exit(2);
	}

	for (i=0; ; ++i)
	{
		printf("%d\n", i);
		sleep(1);
	}

}

void signal_catcher(int the_sig)
{
	/*
	 * Previous spot for the signal funct
	 */
	printf("\nSignal %d received.\n", the_sig);
	if(the_sig == SIGQUIT)
		exit(3);
	/*
	 * I suppose that the author ment for this to be the spot
	 * The funny fact is that either spot requires that you 
	 * hold down the Ctrl+C and not let go then both of them terminate
	 * however the version that he asks for in the program 
	 * does open a window with a very small ammount of time bigger
	 * I suppose that if the question is as to which 
	 * place anywhere in the program then if we put it after the for loop
	 * then it will definately fail no matter how fast the Ctrl-C signals 
	 * sent.
	 */
	signal(the_sig, signal_catcher);

}
/*

[Logged in :       1]
adimitro@alef:/student/adimitro/cwork/ch4> ./a.out
0
1
2
^C
Signal 2 received.
3
^C
Signal 2 received.
4
^C
Signal 2 received.
5
6
^C
Signal 2 received.
7
^C
Signal 2 received.
8
^C
Signal 2 received.
9

^C



^C


^C



[Logged in :       1]
adimitro@alef:/student/adimitro/cwork/ch4>

*/
