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?
how a process know's which child ended?
2.1k Views Asked by orenma At
2
There are 2 best solutions below
2
On
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.
The
wait()syscall returns thepidof the child that terminated. You can callwait()in yourSIGCHLDhandler to determine which child terminated.From the man page: