Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

linux - Signal queuing in C

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What happens is the following:

  1. First signal received, namely SIGUSR1, handler is called and is running
  2. Second signal received, since handler from nr1 is still running, the signal nr2 gets pending and blocked.
  3. Third signal received, since handler from nr1 is still running, the signal 3 gets discarded.
  4. Fourth, fifth...etc signal of the same type as the signal nr1 are discarded.

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...