How to get all descendent child process id of pid in c in linux [duplicate]

孤人 提交于 2019-12-02 02:09:21

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/20533979/how-to-get-all-descendent-child-process-id-of-pid-in-c-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!