c - fork() 的异步信号安全

标签 c linux fork solaris glibc

根据 Oracle 的 Multithreaded Programming Guide , fork() 应该在信号处理程序中安全使用。但是我的进程卡在了信号处理程序内部,跟踪回溯:

 #0  __lll_lock_wait_private () at   ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
 #1  0x00007f86e6a9990d in _L_lock_48 () from /lib/x86_64-linux- gnu/libc.so.6
 #2  0x00007f86e6a922ec in ptmalloc_lock_all () at arena.c:242
 #3  0x00007f86e6ad5e82 in __libc_fork () at ./nptl/sysdeps/unix/sysv/linux/x86_64/../fork.c:95
 #4  0x00007f86e7d9f125 in __fork () at ./nptl/sysdeps/unix/sysv/linux/pt-fork.c:25
....
 #7  signal handler called

既然 malloc 在信号处理程序中使用是不安全的,那 fork 怎么可能呢?

提前致谢。

最佳答案

现在是 listed as a bug by RedHat :

Bug 1422161 - glibc: fork is not async-signal-safe

...

+++ This bug was initially created as a clone of Bug #1422159 +++

POSIX requires that fork is async-signal-safe. Our current implementation is not.

关于c - fork() 的异步信号安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41379544/

相关文章:

c - 系统调用基础知识以及该程序的内容

c - GDB - 将串行输出(从 dmesg)重定向到文件,而不是 gdb 输出/TUI?

C <sys/stat.h> 查找文件类型

C的怪异指针运算2

C - 将 IO 定向到管道,然后将其恢复回控制台

xml - 无法使用 expat 编译 GDB 以用于远程调试

在 UNIX 环境下创建守护进程

c - C中的fork过程

c - 只读全局数据的线程安全初始化

php - 无法在命令行上运行 PHP exec()