How to get all descendent child process id of pid

2019-02-26 17:03发布

This question already has an answer here:

If I fork and the child process then exec and creates more child processes (which themselves can create more processes) , how do I get a list of pids of all the descendent process from the first process?

Is there a better way then looping though /proc/ and checking the PPid (the parent of process's id) of each of process?

2条回答
趁早两清
2楼-- · 2019-02-26 17:19

If you are looking for commands to see the process tree, check below commands.

ps -ejH
ps axjf
pstree $PID

Check the man pages of ps and pstree commands.

查看更多
Luminary・发光体
3楼-- · 2019-02-26 17:28

Iterating through /proc is the "standard" way to do this. That's how ps and friends (pstree, etc.) are implemented.

查看更多
登录 后发表回答