linux信号处理程序中的malloc导致死锁 [英] malloc inside linux signal handler cause deadlock
问题描述
首先很抱歉在信号处理程序内部调用malloc :).我也很明白,我们不应该在信号处理程序内部执行任何耗时的任务/这种讨厌的事情.
First of all sorry for calling malloc inside signal handler :).I too understand we should not do any time consuming task/this kind of nasty stuff inside signal handler.
但是我很好奇它崩溃的原因吗?
But i am curious to know the reason why it is crashed ?
#0 0x00006e3ff2b60dce in _lll_lock_wait_private () from /lib64/libc.so.6
#1 0x00006e3ff2aec138 in _L_lock_9164 () from /lib64/libc.so.6
#2 0x00006e3ff2ae9a32 in malloc () from /lib64/libc.so.6
#3 0x00006e3ff1f691ad in ?? () from ..
我在 https://access.redhat.com/solutions/48701.
操作系统:RHEL
推荐答案
malloc()
不是可以从信号处理程序安全调用的函数.这不是异步信号安全功能.
因此,永远不要从信号处理程序中调用malloc().仅允许您从信号处理程序调用一组有限的函数.
请参阅 man信号安全的列表您可以从信号处理程序安全调用的函数.
malloc()
is not a function that can be safely called from a signal handler. It's not a async-signal-safe function.
So, you should never call malloc() from a signal handler. You are only allowed to call a limited set of functons from a signal handler.
See the man signal-safety for the list of functions you can safely call from a signal handler.
查看您的GDB输出,似乎在malloc()
持有锁的同时,您再次调用malloc()
会导致死锁.
Looking at your GDB output, it appears that while malloc()
is holding a lock, you are calling malloc()
again which results in a deadlock.
这篇关于linux信号处理程序中的malloc导致死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!