1

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

David
  • 481
  • 5
  • 14
  • Possible duplicate of [How can I get the CPU usage and memory usage of a single process on Linux (Ubuntu)?](http://stackoverflow.com/questions/1221555/how-can-i-get-the-cpu-usage-and-memory-usage-of-a-single-process-on-linux-ubunt) – tpsilva Aug 03 '16 at 19:36
  • Possible duplicate of [How to calculate CPU utilization of a process & all its child processes in Linux?](http://stackoverflow.com/questions/12871090/how-to-calculate-cpu-utilization-of-a-process-all-its-child-processes-in-linux) – Rupsingh Aug 08 '16 at 13:55
  • Do you only want to account for direct children of the process, or also children's children? – Armali Aug 11 '16 at 12:27

1 Answers1

0

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 ~
$ 
Taylor Kidd
  • 1,463
  • 1
  • 9
  • 11