All pastes #445533 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-17 22:31 UTC
rendered paste body


#include <signal.h>
#include <stdio.h>
#include <string.h> /* for memset */
#include <sys/time.h>
#include <unistd.h>

int test=0;

/* 1. Implement a signal handler function */
void handler(int signum)
{
	//Set the variable to 1
	test=1;
}

/* main program */

int main(void)
{
	struct sigaction sa;	/* for signal handler settings */
	struct itimerval timer;	/* for timer setting */
	

	
	/* 2. set up the signal handler here */

	memset(&sa, NULL, sizeof(sa));
	sa.sa_handler = handler;
	sigaction(SIGALRM, &sa, NULL);

	/* 3. Set up the periodic timer here*/

	timer.it_interval.tv_usec = 0;
	timer.it_interval.tv_sec = 1;
	timer.it_value.tv_usec = 0;
	timer.it_value.tv_sec = 1;

	/* set up the timer to run */
	setitimer(ITIMER_REAL, &timer, NULL); /* NULL can be replaced with another timer object that
										    will store the old timer settings */

	/* Do some other processing. Nothing extra for exercise */
	while(1)
	{
		if(test==1){
			printf("Test.");
			test=0;
		}
	}

	return 0;
}