On Linux, I want to find all child processes for a given process. I cannot rely on tools like pstree; I need to make use of procfs only.
Since 2012, it has been possible to look up child processes from /prod/PID/task/XXX/children.
Many processes have a single task, but some have a very high number of tasks. It seems there's always a task where task ID is equal to process ID, let's call it the special task, unless someone knows of a better name for it.
If I want to find all child processes for a process with process ID p, do I need to iterate over all tasks, or it it enough to inspect the special task?
(If it's enough to inspect one task, then I'd like to save syscalls and time by not having to iterate over all tasks.)
Documentation states that tid/children is only reliable when everything is stopped, and if not, you are better of traversing all pids. I do not follow why not use pstree, it uses procfs. See https://man7.org/linux/man-pages/man5/proc.5.html .
The 'xxx' part is just thread id. The "special task" is called a "thread group leader" or just the main thread or starting thread.
Yes, you have to iterate over all threads to get all process childs.