digitalmars.com                      
Last update Sun Mar 4 12:00:59 2018

signal.h


raise

Header
signal.h
Prototype
int raise(int sig);
Description
raise issues a signal to the executing program. The signal type, sig, is discussed in the signal description. When the signal is raised by the raise function call, the current signal-handling routine will be called. See signal() for a complete description.
Return Value
Returns 0 if successful, otherwise returns a non-zero value.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
signal
Example
/* Example for raise and signal */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void div_zero(int val) {   
 printf("Divide by zero detected!\n");
 exit(EXIT_FAILURE); 
} 

int main() {   
 float numerator = 3.0F;
 float denominator = 0.0F; 

 if (signal(SIGFPE, div_zero) == SIG_ERR)
 {   
   perror("Could not set signal SIGFPR");
   abort(); 
 } 

 if (denominator == 0.0F)
   raise(SIGFPE); 
 else
   printf("The result of the division is %g\n",
       numerator / denominator);
 return EXIT_SUCCESS;
}
Output
Divide by zero detected! 

signal

Header
signal.h
Prototype
void (*signal(int sig, void (__cdecl *handler)(int)))(int);
Description
signal allows a program to define how signals from the operating system are handled. Argument sig must be one of these constants:

Constant Description
NSIG The number of signals
SIGABRT Abnormal termination
SIGBREAK Control-break
SIGFPE Floating-point error
SIGILL Illegal instruction
SIGINT Interrupt
SIGSEGV Segment violation
SIGTERM Terminate (CTRL+ C)

The following macros are special values for handler:

Macro Description
SIG_DFL Handled in the default manner.
SIG_IGN Ignored the signal.

signal sets the response. handler must be declared with C linkage. When a signal occurs, the signal's behavior is reset to SIG_DFL, the function for signal is called and sig is passed to it.

Return Value
Returns the previous value of handler. A return value of SIG_ERR indicates an error and errno is set.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
raise
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums