Case 1 : Default : SA_NODEFER bit cleared

Here, we are not using the SA_NODEFER signal flag. So, when the first instance of signal n arrives, our process jumps into the signal-handling code (which will take 55 ms to complete). However, the second signal will arrive just 10 ms into the signal handling code. But, hang on, it's auto-masked! Hence, we will not process it. In fact, a simple calculation will show that up to five instances of signal n will reach our process in the 55-ms signal handling time frame:

Figure 3: Default behavior: SA_NODEFER bit cleared: no queue, one signal instance pending delivery, no real impact on stack

So, what exactly happens? Will these five signals be queued up for delivery once the handler completes? Ah! This is an important point: standard or Unix signals are not queued. However, the kernel does understand that one or more signals are pending delivery to the process; hence, once signal handling is done, exactly one instance of the pending signal is delivered (and the pending signal mask is subsequently cleared).

Thus, in our example, even though five signals were pending delivery, the signal handler will get invoked only once. In other words, no signals were queued, but one signal instance was served. This is how signalling works by default.

Figure 3 shows this situation: the dashed signal arrows represent signals that were delivered after entering the signal handler; hence, just one instance is kept pending. Notice the process stack: the signal instance #1 of signal n (obviously) gets a call frame on the stack when the signal handler is invoked, nothing more.

Question: What if the situation is as shown, but another signal, signal m, is delivered?

Answer: If signal m has been caught and is currently unmasked, it will be processed immediately; in other words, it will preempt everything, and its handler will run. Of course, the context is saved by the OS such that whatever got preempted can be later continued once context is restored. This has us conclude the following:

  • Signals are peers; they have no priority associated with them.

  • For standard signals, if several instances of the same integer value are delivered, and that signal is currently masked (blocked), then only one instance is kept pending; there is no queuing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.196.223