Elegantly Get List of Child Processes

processps

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?

Thanks!

Best Answer

Yes, using the -P option of pgrep,

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

Related Question