Catch Signal
2003-05-01 22:01:27
Category: c:linux
Description: This program contains a signal handler so uninterruptable with Ctrl+C keys.
Author: pipas
Viewed: 10335
Rating: (88 votes)


/*
 * Example program by pipas@linux.pte.hu
 * This program is uninterruptable  with
 * Ctrl+C, uses signal handler
 *
 * http://www.metalshell.com/
 */
 
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
 
/* The signal handler function */
void handler( int signal ) {
  printf("Signal handler...\n");
  psignal( signal, "Signal: ");
}  /*handler*/
 
main() {
  /* Registering the handler, catching
     SIGINT signals */
  signal( SIGINT, handler );
 
  /* Do nothing */
  while( 1 ) {
    printf("Running...\n");
    sleep(10);
  }  /*while*/
}  /*main*/