Why is calling a standard library function inside a signal handler discouraged?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Its not only re-entrancy issues, depending on the signal being services you also want to avoid inadvertent calls to malloc() (i.e. asprintf()) and other variadic expansion (i.e. printf()).
This is explained in the GNU LibC documentation.
And just in case, here's the Wikipedia page on reentrant functions.
It is all running fine and stuff, until you run into some mysterious bugs which are totally untraceable :)
man 7 signal
will give you a list of system calls which are safe to call from a signal handler. It is described in POSIX as well.Because the library function may not be reentrant.