我需要澄清一下python中的信号处理程序,因为我不太清楚它们是如何工作的,如何使用它们,以及限制是什么。
我打算在linux上使用USR信号,以便与在后台作为服务运行的python程序进行通信。
我发现,正如预期的那样,我发送的信号似乎是立即以异步方式处理的。
因此,我曾经认为注册的信号处理程序在它们自己的线程中运行,我认为这将解释为什么在循环中发送信号时,下面的代码将同时打印多行Signal handler called with signal 10。
#!/usr/bin/python3.5
# This is the file signal_example.py
import sig
我是否可以区分信号,直接传递给进程和通过调试器传递。
案例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 re
想想看,我猜信号被发送到操作系统,程序将继续进行,即使信号在操作系统端仍处于挂起状态。有人能确认一下吗?
kill(this_process, signum);
printf("will line this run in any reality of the multi-verse?");
printf("or should I go to sleep?");
sleep(10);