
	/* this program acts as an alarm clock.  When called like so:

	            alarmclock  nseconds  alarmprog  [ args ... ]

	   the program 
	                  a. forks, and waits 'nseconds' seconds
	                  b. if not killed yet, it invokes 'alarmprog'

	   intended for use by programs that are afraid that the next
	   process they exec will hang somewhere.  The way they should
	   call it is, for example, like so:

	                  alarmclock 60 unhang
	                  (call process that should take less than 60 seconds)
	                  if (process returns)
	                       killalarm
	                  endif

	   By calling an appropriate 'alarmprog', a hang may be averted.  
	   Note that the anxious program should ignore the status of the
	   'killalarm' call, since if the alarm DOES go off, the alarm proc
	   won't be around anymore by the time the anxious program tries to
	   kill it.

	   This program exits with code 0 if all ok, or 1 if there's a problem.
	*/

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


main(argc, argv)
int argc;
char *argv[];
{
	int i, pid, nseconds;

	if (argc < 3) {
		fprintf(stderr, "usage: alarmclock nseconds alarmprog [ args ... ]\n");
		exit(1);
	}
	if (sscanf(argv[1], "%d", &nseconds) != 1) {
		fprintf(stderr, "alarmclock: can't read number of seconds from arg ..%s..\n",
				argv[1]);
		exit(1);
	}

	if ((pid = fork()) == 0) {
		sleep(nseconds);
		execvp(argv[2], argv + 2);
	}
	else {
		exit(0);
	}

}
