How can i determine the CPU usage of particular processes like mysqld,httpd etc. using shell script?
on bash ...
ps -aecv | grep "your app" | awk '{print $11}'
But it doesn't show the cumulative cpu usage of a application?
It shows the cpu usage at a time in percent
[root@mypbxadmin ~]# ps aecv
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
2954 pts/0 R+ 0:00 0 74 8289 696 0.0 ps
6003 tty1 Ss+ 0:00 0 10 3781 492 0.0 mingetty
6004 tty2 Ss+ 0:00 0 10 3781 492 0.0 mingetty
6005 tty3 Ss+ 0:00 0 10 3781 492 0.0 mingetty
6006 tty4 Ss+ 0:00 0 10 3781 488 0.0 mingetty
6007 tty5 Ss+ 0:00 0 10 3781 492 0.0 mingetty
6009 tty6 Ss+ 0:00 0 10 3781 492 0.0 mingetty
18939 pts/0 Ss 0:00 0 710 65385 1540 0.0 bash
19106 pts/0 S 0:00 0 710 10221 1492 0.0 bash
[root@mypbxadmin ~]# ps -C openser
PID TTY TIME CMD
6059 ? 00:00:00 openser
6089 ? 00:00:31 openser
6091 ? 00:00:31 openser
6093 ? 00:00:30 openser
6094 ? 00:00:31 openser
6096 ? 00:00:30 openser
6098 ? 00:00:31 openser
6100 ? 00:00:30 openser
6102 ? 00:00:30 openser
6104 ? 00:00:07 openser
6106 ? 00:00:00 openser
6108 ? 00:00:00 openser
6110 ? 00:00:00 openser
6112 ? 00:00:00 openser
6114 ? 00:00:00 openser
6116 ? 00:00:00 openser
6118 ? 00:00:00 openser
6120 ? 00:00:00 openser
6122 ? 00:00:00 openser
6126 ? 00:00:00 openser
[root@mypbxadmin ~]# ps aecv | grep "openser" | awk '{print $11}'
No output
NOT
ps aecv
BUT
ps -aecv
use command below
prstat
BR
[root@wiki ~]# ps -aecv |grep "mysql"| awk '{print $11}'
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ