Like adviced in this post I use libproc
to get a list of all running processes. In comparison to the treeview of htop
miss I the ability to get all child processes of a parent process. Is there a way or function to get them?
3 Answers
You can pull the parent-pid from the child's info provided by /proc/<child-pid>/stat
.
As far as I know /proc
does not provide this info the other way round.
To get the tree just read in the parent-pid attribute for all pids and then build up the reverse index yourself.

- 69,737
- 10
- 105
- 255
-
One of the main problems is that the `/proc` (and the `libproc` also) didn't lists the child-pids at all. So I only get the parent-pids and not the child-pids. – arbyter Jun 19 '13 at 07:13
-
@arbyter: Yes sure, but knowing who is the parent-pid of a pid makes you know that this pid is the child of what it carries as it's parent. So you are capable to build the tree your own, **after** you read out the parent-pid for **all* pids. – alk Jun 19 '13 at 07:32
In /proc/<pid>/task
I have found what I had searched for. All child-processes are listed there. Unfortunately I have to write my own code to get the infos out of the structure, but that should be manageable :).

- 539
- 1
- 4
- 12
If you're struck using libproc
(e.g. on systems without linux's /proc
filesystem), you can use proc_listpids
.
XNU (macOS' kernel) also offers proc_listchildpids
, which just calls proc_listpids
, but returning the number of PIDs instead of raw byte count.
int
proc_listchildpids(pid_t ppid, void * buffer, int buffersize)
{
int numpids;
numpids = proc_listpids(PROC_PPID_ONLY, (uint32_t)ppid, buffer, buffersize);
if (numpids == -1) {
return -1;
} else {
return numpids / sizeof(int);
}
}
I feel like that's more of a trap than a convience, so I just prefered to call proc_listpids
directly, myself.

- 59,041
- 12
- 98
- 151