I am trying to find out how can I send a signal to 3 child processes in the same exact fraction of a second. Can you explain to me exactly why it's either possible or not?
If it is possible, can you help me understand using some code in C with kill()
?
The POSIX specification for kill()
gives several ways of sending a signal to multiple processes:
If pid is 0, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the process group ID of the sender, and for which the process has permission to send a signal.
If pid is -1, sig shall be sent to all processes (excluding an unspecified set of system processes) for which the process has permission to send that signal.
If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, and for which the process has permission to send a signal.
Your request is for 'all children'. That isn't feasible if any of the children have changed the process group ID — and that is something they're at liberty to do. Also, if any of the children have since executed a SUID program, you may well have lost permission to send them signals.
The pid value of -1
is quite dangerous; I believe it would go to all processes with the same (effective) UID as the current process.