I'm using the following command to gather the information of child-PID:
top -b -n1 -p 719011,719012,719013,719014,719015,719016,719017 | sed -e 's/USER/----/' -e 's/root/----/' -e 's/PR/--/' -e 's/20/--/' -e 's/VIRT/----/' -e 's/538m/----/' -e 's/RES/---/' -e 's/12m/---/' -e 's/SHR/---/' -e 's/1348/----/' -e 's/NI/--/' -e 's/S/-/' | tail -9 > file1
It works just fine, but is a little long winded! I want to know if there is anyway to gather the information just by using the pPID? Thus saving having to type every child process ID. I don't want the full answer just a pointer in the right direction so I can figure it out myself!
Okay, so I have tidied up the command to:
ps -o pid= --ppid 719008 | top -b -n4 | awk '{print $1,$9,$10,$12}' | tail -9 > file
But instead of giving the output for the child processes I get the output for every process on the system! What am I missing?
$ pstree -p 719008
dvaudio_server(719008)─┬─{dvaudio_server}(719011)
├─{dvaudio_server}(719012)
├─{dvaudio_server}(719013)
├─{dvaudio_server}(719014)
├─{dvaudio_server}(719015)
├─{dvaudio_server}(719016)
└─{dvaudio_server}(719017)
And the output of pgrep
is:
pgrep: option requires an argument -- 'd'
Usage: pgrep [-flvx] [-d DELIM] [-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]
[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] [PATTERN]
You can obtain the direct children of a process using
pgrep
:And:
So:
You can use
ps
to display a list of processes. It understands the--ppid PPIDLIST
argument which allows you to filter the processes by a comma-separated list of parent process IDs.From
man ps
:So probably you should try something like