when a process child is terminated he's sending a SIGCHLD
to the parent process. Now, if the parent process have more than one child how the parent process knows which child had sent the signal?
The wait()
syscall returns the pid
of the child that terminated. You can call wait()
in your SIGCHLD
handler to determine which child terminated.
From the man page:
wait(): on success, returns the process ID of the terminated child;
on error, -1 is returned.
In addition to the wait()
family of calls as in @shanet's answer, the SIGCHLD itself carries that information.
The si_pid
member of the siginfo_t
member passed to a three-argument signal handler (SA_SIGINFO) contains the child's PID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With