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

typedef void (*sighandler_t)(int);

int pid;

void timeout(int sig)
{
	kill(pid, SIGTERM);
	printf("Process %d killed by timeout\n");
}

int main(int argc, char *argv[])
{
	sighandler_t istat;

	printf("grep will sit and wait\n");
	if ((pid = fork()) == 0)
	{
		if (execlp("grep", "grep", "xxx", 0) == -1)
		{
			perror("exec failed");
			exit(1);
		}
	}
	signal(SIGALRM, timeout);
	alarm(10);

	istat = signal(SIGINT, SIG_IGN);
	wait();
	signal(SIGINT, istat);

	printf("Done!\n");
}

