由于printf不是可重入的,因此在信号处理程序中使用它并不安全.但我已经看到很多使用printf这种方式的示例代码.
所以我的问题是:我们何时需要避免printf在信号处理程序中使用,是否有推荐的替代品?
I write my own shell (source code is listed below) and set user's default shell to it.
I login with this user and type ctrl-C, and this shell is killed even though this signal is catched. However, I run this shell directly from bash, it works as I expect. What makes the difference.
Login with user whose default shell is set to my own shell:
BMC login:
BMC login: naroot
Password:
BMC > signal = 2
BMC login: …Run Code Online (Sandbox Code Playgroud)