Call only asynchronous-safe functions within signal handlers. This restriction applies to library functions as well as application-defined functions.
Wiki Markup |
---|
According to Section 7.14.1.1 of the C Rationale \[[ISO/IEC 03|AA. C References#ISO/IEC 03]\]: |
...
This program has four potential problems. The first is that the log_message()
function calls it is unsafe to call the fprintf()
, which is an unsafe function to call from within a signal handler , because the handler might have been may be called when global data (such as stderr
) was is in an inconsistent state. In general, standard I/O is never it is not safe to invoke I/O functions within a signal handler.
Wiki Markup |
---|
The second problem is that the {{free()}} function is also not \[[asynchronous-safe|AA. C References#asynchronous-safe]\], and its invocation from within a signal handler is also a violation of this rule. If an interrupt signal is received during the {{free()}} call in {{main()}}, the heap may be corrupted. |
...
Wiki Markup |
---|
The following table from the the Open Group Base Specifications \[[Open Group 04|AA. C References#Open Group 04]\] defines a set of functions that are asynchronous-signal-safe. Applications may consequentlyinvoke invokethese themfunctions, without restriction, from signal-catching functions. |
...