cprocesssignalsforksigkill

Will kill be interrupted by a signal?


For example, if I use kill (a function in C library signal.h) to emit a SIGINT signal to a child, will the SIGCHLD signal from the child be caught before the kill function returns?


Solution

  • While the kill syscall isn't interruptible (at least according to the man page), there's still at least two cases in which the SIGCHLD handler could run before the function returns:

    1. If there's another thread in your process, the kernel could choose to run the signal handler there even before the kill syscall returns in your first thread.
    2. You're probably using a wrapper function for kill from your libc. The signal handler could run in between the syscall returning to it, and it returning to your code.

    So if you want to make sure you don't get the SIGCHLD until after kill returns, then you need to use sigprocmask to block it before the kill until you're ready for it.