Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 713
Bilal Syed Hussain Avatar asked Oct 02 '22 04:10

Bilal Syed Hussain


1 Answers

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

like image 110
oakad Avatar answered Oct 10 '22 04:10

oakad