
/* Code covered under 3-Clause BSD License - see LICENSE file for details */

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

static int nsigs;
static int otherpid;

sig_t sigsub(void);


sig_t
sigsub()
{
	kill(otherpid, SIGALRM);
	if (--nsigs <= 0)
		exit(0);

	return signal(SIGALRM, (sig_t)sigsub);
}


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

	if (argc < 2) {
		printf("usage: %s #signals\n", argv[0]);
		exit(1);
	}

	nsigs = atoi(argv[1]);
	signal(SIGALRM, (sig_t)sigsub);
	otherpid = getpid();
	pid = fork();

	if (pid != 0) {
		otherpid = pid;
		kill(otherpid, SIGALRM);
	}

	for(;;)
		sigpause(0);

	return 0;
}


