From 2cefa3af76c0ab3bbf75b9cd6f486327dc52d2d8 Mon Sep 17 00:00:00 2001 From: Force Charlie Date: Mon, 20 May 2019 12:55:57 +0800 Subject: [PATCH] Async Signal Safe --- cpp/asyncsignalsafe.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cpp/asyncsignalsafe.md diff --git a/cpp/asyncsignalsafe.md b/cpp/asyncsignalsafe.md new file mode 100644 index 0000000..0957932 --- /dev/null +++ b/cpp/asyncsignalsafe.md @@ -0,0 +1,19 @@ +# 异步信号安全 BUG. + +在信号回调函数中需要注意异步信号安全问题,不能使用任何非异步信号安全的函数,因为在信号回调函数中,其他代码可能会持有锁,在信号回调函数中再次调用锁导致死锁。此 BUG 曾在 SSHD 中出现,git-srv 也曾出现过此问题。POSIX 系统中,很多软件也没有处理好异步信号安全。 + +```c++ +#include + +void handler(int sig){ + printf ("child exit !\n" ); +} + + +int main(){ + signal(SIGCHLD,handler); + // TODO oter code + return 0; +} + +``` -- Gitee