in reply to waitpid for child #1 inside child #2: any way to make it work?
Question: Is there a way to make child #2 know about $pid1 such that waitpid($pid1) inside child #2 works?
No. waitpid($pid1) inside child #2 will never work.The parent waits for the child, not the other way round. Grandfather doesn't wait for grandsons, and the reverse holds, too.
For the first child (which you name parent2), $pid1 is the parent pid. Inside that child you can get at the $pid1 via getppid. If you want to get the pid from the grandfather in the grandson, the grandson has to ask its father via some other IPC mechanism. Then the grandson may kill 0, $grandfatherpid to see if the grandfather process is still alive. See kill.
|
|---|