-2

APUE says

Since the process group is orphaned when the parent terminates, and the process group contains a stopped process, POSIX.1 requires that every process in the newly orphaned process group be sent the hang-up signal (SIGHUP) followed by the continue signal (SIGCONT).

The kernel sends SIGCONT after SIGHUP, but the process is waken up by SIGCONT before acting on SIGHUP. So why doesn't the Linux kernel send SIGCONT before SIGHUP?

Thanks.

Related to but not answered by Does the default action of SIGCONT resume the execution of a stopped process before or after first handling any pending unblocked signals?


I did not answer my question.

  • 3
    You just answered your own question; to ensure SIGHUP is pending and so handled when the process is resumed. – Stephen Harris Dec 26 '18 at 13:58
3

Not only do you answer your question, the link you added at the end also answers your question.

When a process is stopped, all signal processing is stopped, except for SIGCONT and SIGKILL - which are, in practice handled by the operating system.

This means that SIGHUP can only the handled after the process is resumed, which happens when SIGCONT is recieved and handled, so, even if you send a SIGHUP followed by a SIGCONT, they are going to be handled in the opposite order.

Now, in practice, the kernel sending SIGHUP before will result in less stuff being done by a process between handling SIGCONT and handling SIGHUP, as the second is already queued to be handled.

  • This is the part that I am not sure: "if you send a SIGHUP followed by a SIGCONT, they are going to be handled in the opposite order." – Tim Dec 26 '18 at 20:13
  • Hi @Tim. If the process is stopped, they have to be, because until the process handles SIGCONT, it doesn't handle any other signal, except SIGCONT and SIGKILL. – theMage Dec 27 '18 at 9:09
  • So isn't it the same reacting order, regardless of sending order? – Tim Dec 27 '18 at 12:29
  • It is. However, you can't warranty that the process sending the signals will not be paused between serving the two signals, which would, potentially, resulting in the second process doing other stuff between handling the two signals. – theMage Dec 27 '18 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.