gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:59:34 25 4
gpt4 key购买 nike

根据 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com