简体   繁体   中英

How to find orphan process's pid

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.

ie,

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 (eg in a file or by reporting back to the father process (PID 1 in your example) via pipes or similar).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM