I would like to know the CPU and memory usage of a process and all of its children processes in Linux.
it would be better to have solution using ps command.but other solutions are also welcome.
Please help
Thanks Shuja
I would like to know the CPU and memory usage of a process and all of its children processes in Linux.
it would be better to have solution using ps command.but other solutions are also welcome.
Please help
Thanks Shuja
Here's a simple script to do what you want. Your options will vary depending upon the version of 'ps' you are using. The result is comma delimitated so you can pass it into a spread sheet.
ps -vl | awk '{print $1 ", " $11 ", " $12 ", " $15}' | sed -n '/^424/ p'
where you change the 424 into whatever parent PID you want. Of course, if there's something else with the same digits as your PID, you'll have to be a little careful.
Someone ~
$ ps -vl
PID STAT TIME SL RE PAGEIN VSZ RSS LIM TSIZ %CPU %MEM COMMAND UID PPID F CPU PRI NI WCHAN ADDR TTY
432 S+ 0:00.01 0 0 0 2499948 1696 - 0 0.0 0.0 -bash 501 431 4006 0 31 0 - 0 ttys001
618 S 0:00.06 0 0 0 2465132 1656 - 0 0.0 0.0 -bash 501 617 4006 0 31 0 - 0 ttys002
424 S+ 0:00.01 0 0 0 2482540 1620 - 0 0.0 0.0 -bash 501 423 4006 0 31 0 - 0 ttys000
629 S+ 0:00.02 0 0 0 2463084 1612 - 0 0.0 0.0 -bash 501 628 4006 0 31 0 - 0 ttys003
Someone ~
$ ps -vl | awk '{print $1 ", " $11 ", " $12 ", " $15}' | sed -n '/^424/ p'
424, 0.0, 0.0, 423
Someone ~
$