How to avoid using printf in a signal handler?

后端 未结 7 964
青春惊慌失措
青春惊慌失措 2020-11-21 06:35

Since printf is not reentrant, it\'s not supposed to be safe to use it in a signal handler. But I\'ve seen lots of example codes that uses printf t

7条回答
  •  盖世英雄少女心
    2020-11-21 06:36

    How to avoid using printf in a signal handler?

    1. Always avoid it, will say: Just don't use printf() in signal handlers.

    2. At least on POSIX conforming systems, you can use write(STDOUT_FILENO, ...) instead of printf(). Formatting may not be easy however: Print int from signal handler using write or async-safe functions

提交回复
热议问题