I just informed myselve about \"signals\" in C/C++ and played around. But i have a problem to understand the logic of SIGFPE
.
I wrote a little program which
Divide by zero is undefined behaviour. So whether you have installed a handler for SIGFPE
or not is of little significance when your program invokes undefined behaviour.
POSIX says:
Delivery of the signal shall have no effect on the process. The behavior of a process is undefined after it ignores a SIGFPE, SIGILL, SIGSEGV, or SIGBUS signal that was not generated by kill(), sigqueue(), or raise().
A signal is raised as a result of an event (e.g. sending SIGINT
by pressing CTRL+C) which can be handled by the process if said event non-fatal. SIGFPE
is an erroneous condition in the program and you can't handle that. A similar case would be attempting to handle SIGSEGV
, which is equivalent to this (undefined behaviour). When your process attempts to access some memory for which it doesn't have access. It would be silly if you could just ignore it and carry on as if nothing happened.