如何在应用程序中使用 strace 找出信号编号?

如何在应用程序中使用 strace 找出信号编号?

请看一下有没有办法知道您的应用程序中是否存在信号以及有哪些信号?Stephen Kitt 在其中分享了一个解决方案 -

strace -e trace=signal ...

现在只是为了知道,玩得开心,明白我运行的命令是 -

$] strace -e trace=signal qbittorrent

当我运行它时,我得到的输出为 -

rt_sigaction(SIGRTMIN, {sa_handler=0x7faabe532bd0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7faabe53e0c0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7faabe532c60, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7faabe53e0c0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x5628b7cd2960, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=0x5628b7cd2960, sa_mask=[TERM], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGABRT, {sa_handler=0x5628b7cd2b00, sa_mask=[ABRT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGSEGV, {sa_handler=0x5628b7cd2b00, sa_mask=[SEGV], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7faabd925030}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0

现在我如何确定应该给出哪个/什么信号号,以便在发生崩溃或其他情况时为维护人员提供更好的调试?

期待知道。

答案1

一般来说,你不能。

strace 输出显示正在处理哪些信号,但这取决于每个应用程序如何(或不)生成调试输出。也许他们在收到 SIGHUP 时执行此操作,也许在收到 SIGUSR1 时执行此操作,或者可能在收到-D启动标志时执行此操作,或者根本不执行此操作。

相关内容