信号用C排队 [英] signal queuing in C

查看:130
本文介绍了信号用C排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux下一个简单的程序,它发送SIGUSR1信号给其子进程在一个周期。但是,当我发例如10个信号,有时会发生,孩子收到的只有3人。最后发送的信号始终是SIGUSR2和已接收每次。

I have a simple program under Linux which sends SIGUSR1 signal to its child process in a cycle. But when I send e.g. 10 signals, sometimes happens, that the child received only 3 of them. Last sent signal is always SIGUSR2 and that is received every time.

是信号排队,或者在过程中没有处理previous,那简直是覆盖?有没有一种方法,我可以排队发送信号?

Are the signals queuing, or when process didn't process the previous, it is simply overwritten? Is there a way I can send signals in a queue?

推荐答案

会发生什么事是这样的:

What happens is the following:


  1. 接收的第一信号,即SIGUSR1,处理程序被调用,运行

  2. 接收的第二信号,因为从NR1处理程序仍在运行,NR得到信号挂起并阻止。

  3. 接收的第三信号,因为从NR1处理程序仍在运行,信号3被丢弃。

  4. 四,第五...等类型相同NR1被丢弃的信号的信号。

在信号处理与信号NR1完成,它会处理信号NR2,然后信号处理程序将处理SIGUSR2。

Once signal handler is done with signal nr1, it will process signal nr2, and then signal handler will process the SIGUSR2.

基本上,相同类型的挂起信号不排队,而是被忽略。没有,有没有简单的方法来爆发出信号的方式。人们总是假定有可能是被丢弃的几个信号,并试图让处理器做清洁,并找出该怎么做(如收割的孩子,如果所有的孩子在同一时间死亡)的工作。

Basically, pending signals of the same type are not queued, but discarded. And no, there is no easy way to "burst" send signals that way. One always assumes that there can be several signals that are discarded, and tries to let the handler do the work of cleaning and finding out what to do (such as reaping children, if all children die at the same time).

这篇关于信号用C排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆