Is puts reentrant?
Is int puts(const char*);
re-entrant? Can I saf开发者_运维百科ely put it into a signal handler?
Here is a table with all functions considered safe for signal handling:
"The following table defines a set of functions that shall be either reentrant or non-interruptible by signals and shall be async-signal-safe."
puts
does not seem to be in that list, however per this, it is deemed reentrant, but not async-safe, perhaps why it is not in the above mentioned list.
No it is not, you can however use write()
, which is async signal safe, to output messages from a signal handler:
#include <unistd.h>
const char* msg = "The message to print.";
write(STDOUT_FILENO, msg, strlen(msg));
精彩评论