Name
raise - Sends a signal to the executing program.
Syntax
#include <signal.h>
int raise(sig)
int sig;
Description
The raise function sends sig to the executing program. The
default action for sig is taken unless a different action
has been defined using the signal routine.
The signal value sig can be one of the following manifest
constants:
Signal Meaning
SIGABRT abort signal handler, abnormal
termination. The default
action terminates the calling
program with exit code 3.
SIGFPE Floating point exceptions,
floating-point error. The
default action terminates the
calling program.
SIGILL Illegal instruction. This
signal is not generated by DOS
or OS/2, but is supported for
ANSI compatibility. The
default action terminates the
calling program.
SIGINT DOS interrupt, issues INT 23H.
SIGSEGV Illegal storage access. This
signal is not generated by DOS
or OS/2, but is supported for
ANSI compatibility. The
default action terminates the
calling program.
SIGTERM Termination request sent to
the program. This signal is
not generated by DOS or OS/2,
but is supported for ANSI
compatibility. The default
action ignores it.
Return Value
If successful, the raise function returns 0. Otherwise, it
returns a nonzero value.
See Also
abort(DOS), signal(DOS)
Example
#include <stdio.h> #include <signal.h> #include <stdlib.h>
#include <process.h>
void handler(); float num = 1.0; float denom = 0.0;
main()
{
/* Set so interrupt calls "handler" */
if (signal(SIGFPE,handler) == (int(*)())-1)
{
perror("Couldn't set SIGFPE");
abort();
}
if (denom == 0)
raise(SIGFPE);
else
printf("Result of division is %f\n",
num/denom);
}
/* handler subroutine */
void handler() /* Function called at Floating */
{ /* Point Exception interrupt */
char ch;
printf("Inside Floating Point Exception Handler\n");
exit(0);
}
The above program uses raise to detect a division-by-zero
error before the error is actually executed; it also sends
control to the routine defined by signal.
(printed 6/18/89)