tags:

views:

46

answers:

2

I have used following command to fetch the CPU utilization of a process. It is giving result, but it is not coming out. I have used following command.

top | grep <processname>

I just want to put this in a loop and I will insert sleep in the code so that I can fetch the value in regular intervals

A: 

You can do:

while [ 1 ]; do top -n 1 | grep something; sleep 1; done

Use the -n option of top:

-n
    Number of iterations. Update the display this number of times and then exit. 
codaddict
+2  A: 

Use top's batch mode, eg.

top -b -n1 | grep processname
Hasturkun