检测信号发送者(linux、ptrace)
我可以区分直接传递到进程的信号和通过调试器传递的信号吗?
情况 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()
.
人 ptrace: ( http://linux.die.net/man/2/ptrace)
man ptrace: ( http://linux.die.net/man/2/ptrace )