I would like to get a list of all the processes whose parent is $pid. This is the simplest way I've come up with:

pstree -p $pid | tr "\n" " " |sed "s/[^0-9]/ /g" |sed "s/\s\s*/ /g"

Is there any command, or any simpler way to get the list of children processes?


2 Answers 2


Yes, using the -P option of pgrep,

i.e pgrep -P 1234 will get you a list of child process ids.

  • 2
    I'm afraid your answer is correct, but my question was incorrect. Therefore I accept your answer (which I didn't know, btw) and I opened another thread with the question I really meant to ask: unix.stackexchange.com/questions/67668/…
    – STenyaK
    Mar 12, 2013 at 13:59

pids of all child processes of a given parent process <pid> id is present in /proc/<pid>/task/<tid>/children entry.

This file contains the pids of first-level child processes. Do it recursively for whole process tree.

head over to https://lwn.net/Articles/475688/ for more information.

  • 1
    Presence of the file is governed by CONFIG_PROC_CHILDREN. Mar 29, 2021 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.