How can I find child process pid after the parent process died.
I have program that creates child process that continues running after it (the parent) terminates.
i.e.,
I run a program from python script (PID = 2).
The script calls program P (PID = 3, PPID = 2)
P calls fork(), and now I have another instance of P named P` (PID = 4 and PPID = 3).
After P terminates P` PID is 4 and PPID is 1.
Assuming that I have the PID of P (3), how can I find the PID of the child P`?
Thanks.
The information is lost when a process-in-the-middle terminates.  So in your situation there is no way to find this out.
You can, of course, invent your own infrastructure to store this information at forking time.  The middle process (PID 3 in your example) can of course save the information which child PIDs it created (e. g. in a file or by reporting back to the father process (PID 1 in your example) via pipes or similar).
How to find orphan process's pid