/*
* Demo of using the signal/alarm routines to interrupt a program that
* runs for too long.
*/

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

int timeout = 5;	/* Kill the program after this many seconds */

sig_t alrm() {		/* Alarm handler */
	printf("Alarm!\n");
	exit(0);	/* Exit normally */
}

main(ac,av) char **av;
{	int n = 0;
	signal(SIGALRM,(sig_t)alrm);	/* Declare our alarm handler */
	alarm(timeout);	/* Set alarm timer */
	while (++n) {	/* Very long loop */
		printf("%d ...\n",n);
		sleep(1);	/* Don't use (much) cpu time */
	}
	printf("Can't get here.\n");
	exit(1);		/* Paranoia */
}


