Monday, December 21, 2009

Signal Handling

An example of signal handling in C.


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

void
termination_handler (int signum)
{
printf("signal called number %dn", signum);
if(signum == SIGUSR1)
signal (SIGUSR1, termination_handler);
//if(signum == SIGINT)
//signal (SIGINT, termination_handler);
if(signum == SIGUSR2)
signal (SIGUSR2, termination_handler);
}

int main (void)
{
{
signal (SIGUSR1, termination_handler);
perror("??");
signal (SIGUSR2, termination_handler);
perror("??");
//signal (SIGINT, termination_handler);
//perror("??");
}

while(1)
{
sleep(100);
printf("");
}

}

No comments:

Post a Comment