I am trying to capture the process on a red hat linux system with the highest cpu utilization into a variable. I have been playing with ps command but really do not think I am making the correct progress.
For instance:
top - 09:01:16 up 63 days, 18:29, 2 users, load average: 0.39, 0.49, 0.48
Tasks: 175 total, 1 running, 174 sleeping, 0 stopped, 0 zombie
Cpu(s): 13.7% us, 15.1% sy, 0.0% ni, 70.0% id, 0.8% wa, 0.3% hi, 0.0% si
Mem: 15337328k total, 6674076k used, 8663252k free, 388060k buffers
Swap: 6144852k total, 0k used, 6144852k free, 2713480k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2134 nobody 15 0 69272 52m 11m S 14 0.4 2:07.28 httpd
Above the red 14% is what I am after. I have been using this command to try to get it, however not sure it is correct.
[root@vmradio01 ~]# ps -eo pid,user,%cpu,args --sort %cpu |grep httpd | tail -n1 | awk '{print $3}'| awk -F \. '{print $1}'
1
My goal is to capture the process consuming the most cpu usage. So I am running this:
cpuusage=`[root@vmradio01 ~]# ps -eo pid,user,%cpu,args --sort %cpu |grep httpd | tail -n1 | awk '{print $3}'| awk -F \. '{print $1}'`
Any thoughts or suggestions please?
Jaysunn