async-safe

Why only async-safe functions should be called from a signal handler?

六月ゝ 毕业季﹏ 提交于 2019-11-29 17:08:32
I understand that, from a signal handler function sigaction() I should only call those functions that are "async-safe". But why is so? Calling an unsafe function may lead to undefined behavior. The Open Group Base Specifications Issue 7 (POSIX.1-2008), in its treatment of "Signal Concepts" , says: [W]hen a signal interrupts an unsafe function ... and the signal-catching function calls an unsafe function, the behavior is undefined. As to why unsafe functions are unsafe, there may be many reasons in a given implementation. However, a previous version of the standard, Issue 6 (POSIX.1-2004),

Why only async-safe functions should be called from a signal handler?

十年热恋 提交于 2019-11-28 10:48:51
问题 I understand that, from a signal handler function sigaction() I should only call those functions that are "async-safe". But why is so? 回答1: Calling an unsafe function may lead to undefined behavior. The Open Group Base Specifications Issue 7 (POSIX.1-2008), in its treatment of "Signal Concepts", says: [W]hen a signal interrupts an unsafe function ... and the signal-catching function calls an unsafe function, the behavior is undefined. As to why unsafe functions are unsafe, there may be many

Print int from signal handler using write or async-safe functions

别来无恙 提交于 2019-11-26 22:51:42
I want to print a number into log or to a terminal using write (or any async-safe function) inside a signal handler. I would prefer not to use buffered I/O. Is there an easy and recommended way to do that ? For example in place of printf , below I would prefer write (or any asyn safe function). void signal_handler(int sig) { pid_t pid; int stat; int old_errno = errno; while((pid = waitpid(-1, &stat, WNOHANG)) > 0) printf("child %d terminated\n", pid); errno = old_errno; return; } Printing strings is easy. In place of the printf above I can use (without printing pid ): write(STDOUT_FILENO,

I need a list of Async-Signal-Safe Functions from glibc

隐身守侯 提交于 2019-11-26 16:37:35
问题 Non syscall's wrappers but something like snprintf(), dprintf() 回答1: I am pretty sure you have to see the documentation Edit : How about this list then? From man signal : NOTES The effects of this call in a multi-threaded process are unspecified. The routine handler must be very careful, since processing elsewhere was interrupted at some arbitrary point. POSIX has the concept of "safe function". If a signal interrupts an unsafe function, and handler calls an unsafe function, then the behavior

Print int from signal handler using write or async-safe functions

笑着哭i 提交于 2019-11-26 08:29:27
问题 I want to print a number into log or to a terminal using write (or any async-safe function) inside a signal handler. I would prefer not to use buffered I/O. Is there an easy and recommended way to do that ? For example in place of printf , below I would prefer write (or any asyn safe function). void signal_handler(int sig) { pid_t pid; int stat; int old_errno = errno; while((pid = waitpid(-1, &stat, WNOHANG)) > 0) printf(\"child %d terminated\\n\", pid); errno = old_errno; return; } Printing