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?
Signal Queue: Each process maintains a queue of signals it has received but not yet processed. A signal that has been blocked using a mask will be queued up. The process can access this queue through sigwait (), sigwaitinfo (), and similar functions.
Signals in C language. A signal is a software generated interrupt that is sent to a process by the OS because of when user press ctrl-c or another process tell something to this process. There are fix set of signals that can be sent to a process. signal are identified by integers. Signal number have symbolic names.
Queue in C is a data structure that is not like stack and one can relate the behavior of queue in real -life. Unlike stack which is opened from one end and closed at the other end which means one can enter the elements from one end only.
If user presses ctrl-c to terminate the process because of SIGINT signal sent and its default handler to terminate the process. A process can replace the default signal handler for almost all signals (but not SIGKILL) by its user’s own handler function.
What happens is the following:
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).
If multiple signals of the same type are sent and not handled, they aren't queued. Say the program masks SIGUSR1
, calls kill(getpid(), SIGUSR1)
10 times and unmasks SIGUSR1
. It will receive SIGUSR1
just once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With