I'm trying to figure out the easiest way to have a parent process send a signal to all of its children in a C program written in a Linux environment.
Obviously, the easiest way to signal a particular child process is using the kill system call, and passing it the PID of the child. But if you don't have the PID of the child, or you want to send a signal to ALL children, is there an easy way to do it?
I realize that you can pass PID 0 to kill(), which will send a signal to every process in the current process group. Unfortunately, this includes the parent as well. (I could have the parent block signals, and then have all children unblock, but this seems cumbersome.)
The man page for kill() also says the following:
"If pid is less than -1, then sig is sent to every process in the process group -pid."
I'm not sure what this means. What does "in the progress group minus pid" mean? Regardless, I tried passing PID -2 to kill, and it had no effect at all.
So, what is the best way to have the parent process send a signal to all of its children?