检测信号发送者(linux、ptrace)

发布于 2024-08-26 19:44:21 字数 692 浏览 7 评论 0原文

我可以区分直接传递到进程的信号和通过调试器传递的信号吗?

情况 1:

 $ ./process1
 process1 (not ptraced)
 //set up handler
 alarm(5);
 ....
 //signal is handled and I can parse handler parameters

情况 2:

 $ debugger1 ./process1
 process1 (is ptraced by debugger1)
 //set up handler
 alarm(5);
 ...
 //signal is catched by debugger1. It resumes process1 with PTRACE_CONT,
 // signal_number is 4th parameter of PTRACE_CONT.
 //signal is redelivered to process1
 //and then is handled.

那么,我如何在信号处理程序中检测它是由调试器重新传递还是由系统发送?

操作系统是Linux,内核是2.6.30。程序是用纯 C 语言编写的。在实际程序中使用了 SIGALRM,但它不是由 alarm() 生成的,而是由 setitimer() 生成的。

Can I distinguish signal, between delivered directly to a process and delivered via debugger.

Case 1:

 $ ./process1
 process1 (not ptraced)
 //set up handler
 alarm(5);
 ....
 //signal is handled and I can parse handler parameters

Case 2:

 $ debugger1 ./process1
 process1 (is ptraced by debugger1)
 //set up handler
 alarm(5);
 ...
 //signal is catched by debugger1. It resumes process1 with PTRACE_CONT,
 // signal_number is 4th parameter of PTRACE_CONT.
 //signal is redelivered to process1
 //and then is handled.

So, how can I detect in signal handler, was it redelivered by debugger or send by system?

OS is Linux, kernel is 2.6.30. Programs are written in plain C. In real program SIGALRM is used, but it is generated not by alarm(), but with setitimer().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请恋爱 2024-09-02 19:44:21

人 ptrace: ( http://linux.die.net/man/2/ptrace)

PTRACE_GETSIGINFO(自 Linux
2.3.99-pre6) 检索有关导致停止的信号的信息。
复制 siginfo_t 结构(请参阅
sigaction(2)) 从孩子到
父级中的位置数据。 (地址是
忽略。)

PTRACE_SETSIGINFO(自 Linux
2.3.99-pre6) 设置信号信息。复制 siginfo_t 结构
父级中的位置数据
孩子。这只会影响信号
通常会交付给
孩子被抓住了
示踪剂。 可能很难说
这些来自合成的正常信号
ptrace() 生成的信号
本身。 (地址被忽略。)

PTRACE_CONT 重新启动已停止的
子进程。如果数据非零且
不是 SIGSTOP,它被解释为
向孩子发出的信号;
否则,不会传送信号。
因此,例如,父母可以
控制信号是否发送到
孩子是否出生。 (地址是
忽略。)

man ptrace: ( http://linux.die.net/man/2/ptrace )

PTRACE_GETSIGINFO (since Linux
2.3.99-pre6) Retrieve information about the signal that caused the stop.
Copies a siginfo_t structure (see
sigaction(2)) from the child to
location data in the parent. (addr is
ignored.)

PTRACE_SETSIGINFO (since Linux
2.3.99-pre6) Set signal information. Copies a siginfo_t structure from
location data in the parent to the
child. This will only affect signals
that would normally be delivered to
the child and were caught by the
tracer. It may be difficult to tell
these normal signals from synthetic
signals generated by ptrace()
itself
. (addr is ignored.)

PTRACE_CONT Restarts the stopped
child process. If data is non-zero and
not SIGSTOP, it is interpreted as a
signal to be delivered to the child;
otherwise, no signal is delivered.
Thus, for example, the parent can
control whether a signal sent to the
child is delivered or not. (addr is
ignored.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文