SIGFPE
From Wikipedia, the free encyclopedia
Description: | Erroneous arithmetic operation |
---|---|
Default action: | Abnormal termination of the process |
SA_SIGINFO macros | |
FPE_INTDIV |
Integer divide by zero |
FPE_INTOVF |
Integer overflow |
FPE_FLTDIV |
Floating-point divide by zero |
FPE_FLTOVF |
Floating-point overflow |
FPE_FLTUND |
Floating-point underflow |
FPE_FLTRES |
Floating-point inexact result |
FPE_FLTINV |
Invalid floating-point operation |
FPE_FLTSUB |
Subscript out of range |
SIGFPE is the signal sent to computer programs that perform erroneous arithmetic operations on POSIX compliant platforms. The symbolic constant for SIGFPE is defined in the header file signal.h
. Symbolic signal names are used because signal numbers can vary across platforms.
Contents |
[edit] Etymology
SIG is a common prefix for signal names; FPE is an acronym for floating-point exception. Although SIGFPE does not necessarily involve floating-point arithmetic, there is no way to change its name without breaking backward compatibility.
[edit] Description
SIGFPE is sent to processes for a variety of reasons. A common example might be an unexpected type overflow (eg, unsigned integer) due to exceptional input, or an error in a program construct.
SIGFPE can be handled. That is, programmers can specify the action they want to occur on receiving the signal, such as calling a subroutine, ignoring the event, or restoring the default action.
Under certain circumstances, ignoring SIGFPE can result in undefined behaviour. In particular, the program may hang as the offending operation is forever retried. However, it is safe to ignore SIGFPE signals not actually resulting from computation, such as those sent via the kill
system call.
A common oversight is to consider division by zero the only source of SIGFPE conditions. On some architectures (IA-32 included), integer division of INT_MIN, the smallest representable negative integer value, by −1 triggers the signal because the quotient, a positive number, is not representable.
[edit] Example
Here is an example of an ANSI C program that attempts to perform an erroneous arithmetic operation, namely integer division by zero, or FPE_INTDIV.
int main() { int x = 42/0; }
Compiling and running it on IA-32 with Linux produces the following:
$ gcc -o sigfpe sigfpe.c sigfpe.c: In function ‘main’: sigfpe.c:3: warning: division by zero $ ./sigfpe Floating point exception (core dumped)
A backtrace from gdb shows that the SIGFPE signal occurred in the main
function:
Program received signal SIGFPE, Arithmetic exception. 0x08048373 in main ()
Compare the output from SIGFPE with that of a segmentation fault or the SIGILL signal for illegal instructions.
[edit] See also
POSIX Signals |
SIGABRT | SIGALRM | SIGFPE | SIGHUP | SIGILL | SIGINT | SIGKILL | SIGPIPE | SIGQUIT | SIGSEGV | SIGTERM | SIGUSR1 | SIGUSR2 | SIGCHLD | SIGCONT | SIGSTOP | SIGTSTP | SIGTTIN | SIGTTOU | SIGBUS | SIGPOLL | SIGPROF | SIGSYS | SIGTRAP | SIGURG | SIGVTALRM | SIGXCPU | SIGXFSZ | Realtime Signals are user definable—SIGRTMIN+n through SIGRTMAX. |
Common non-POSIX signals and synonyms |
SIGIOT | SIGEMT | SIGSTKFLT | SIGIO | SIGCLD | SIGINFO | SIGPWR (SIGINFO) | SIGLOST | SIGWINCH | SIGUNUSED |