gdb调试的程序所注册的信号处理函数似乎不起作用,因此需要在gdb中设置对信号的处理,使用handle命令。可以设置stop,print,pass三种状态。
(gdb) help handle
Specify how to handle a signal.
Args are signals and actions to apply to those signals.
Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals
from 1-15 are allowed for compatibility with old versions of GDB.
Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).
The special arg "all" is recognized to mean all signals except those
used by the debugger, typically SIGTRAP and SIGINT.
Recognized actions include "stop", "nostop", "print", "noprint",
"pass", "nopass", "ignore", or "noignore".
Stop means reenter debugger if this signal happens (implies print).
Print means print a message if this signal happens.
Pass means let program see this signal; otherwise program doesn't know.
Ignore is a synonym for nopass and noignore is a synonym for pass.
Pass and Stop may be combined.
(gdb) handle SIGPIPE
Signal Stop Print Pass to program Description
SIGPIPE Yes Yes Yes Broken pipe
(gdb) handle SIGPIPE nostop
Signal Stop Print Pass to program Description
SIGPIPE No Yes Yes Broken pipe
ps1:Linux内核对一个socket的fd write的时候如果另一端挂掉了,那么会出现抛出SIGPIPE信号,FreeBSD就比较酷,在05年的时候修正了这个无厘头的行为
ps2:python默认会忽略SIGPIPE信号
ref1:http://www./forum/showthread.php?t=2953
ref2:http://lists./pipermail/freebsd-bugs/2005-March/011883.html
ref3:http://mail./pipermail/python-dev/2004-August/048174.html