Home > Electronics Tutorials > C Language Tutorial > signal.h - raise

C Language Programming Library Reference Guide

signal.h - raise

Declaration int raise(int sig); Causes signal sig to be generated. The sig argument is compatible with the SIG macros.

If the call is successful, zero is returned. Otherwise a nonzero value is returned.

Example:

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

void catch_function(int);

int main(void)
{
  if(signal(SIGINT, catch_function)==SIG_ERR)
   {
    printf("An error occured while setting a signal handler.\n");
    exit(0);
   }

  printf("Raising the interactive attention signal.\n");
  if(raise(SIGINT)!=0)
   {
    printf("Error raising the signal.\n");
    exit(0);
   }
  printf("Exiting.\n");
  return 0;
}

void catch_function(int signal)
{
  printf("Interactive attention signal caught.\n");
}
The output from the program should be (assuming no errors):
 
Raising the interactive attention signal.
Interactive attention signal caught.
Exiting.
Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......