Tuesday, May 29, 2012

Signal Handling in Unix

A signal is fundamentally an asynchronous call back for processes in Linux. we can register to receive a signal when an event occurs for a process or register to ignore signals.

signal are an important topic here process management because they allow processes to communicate with one another. We can use Signal API function to register our handler.

Example:
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>

void catch_ctlc( int sig_num)
{
printf("Caught control c.\n");
fflush(stdout);
return;
}
int main ()
{
signal (SIGINT,catch_ctlc);// Registering our call back function.
printf("\n Go ahead , make my day \n");
pause();//It suspended the process until a signal is received.

return 0;
}

No comments:

Post a Comment

Qualcomm Short Term

  113 is the SL. 1st Target by mid July.

Total Pageviews