This blog is under construction

Saturday, 5 May 2012

raise

Header file:
    signals.h

Synopsis:
     int raise(int sig);

Description:
     It sends the signal sig to the caller and returns non-zero on failure.


Sample program for raise in C:



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

  static void sig_alarm(int signo) {
        if(signo == SIGUSR1)
                printf("SIGUSR1 catched\n");
        exit(0);
  }

  int main() {
        if(signal(SIGUSR1, sig_alarm) == SIG_ERR)
                printf("Unable to catch SIGALARM\n");
        while(1) {
                sleep(5);
                raise(SIGUSR1);
        }
  }




  Output:
  jp@jp-VirtualBox:~/cpgms/signals$ ./a.out
  SIGUSR1 catched


No comments:

Post a Comment