-   Linux - Newbie (
-   -   shell program to find a process load (

ttsdinesh 11-29-2009 08:52 PM

shell program to find a process load
I need to find the CPU load being used by a particular process,say for example "java".Also i need to write that process's load to a file. i used the following command:

But it lists all the processes and their load. I need just the load of java alone. Is there any way to parse the output or somebody help me with a shell program?

jiobo 11-29-2009 08:54 PM


top | grep java

bret381 11-29-2009 08:54 PM

add " | grep java > newfilename"

ttsdinesh 11-29-2009 08:57 PM

Let me try and will get u back Dudes.

evo2 11-29-2009 09:34 PM

Have a look at the top man page. Specifically regarding the -b flag for batch mode.


vishesh 11-29-2009 10:12 PM

what about
root#top -b -d 5 -p <pid of process>

-b -> in batch mode
-d-> Delay


ttsdinesh 12-01-2009 07:52 PM

I tried with

top | grep java
. But it prints the entire line

ubuntu@ubuntu:~$top | grep Xorg
4102 root 20 0 41748 13m 6832 S 7.3 2.7 0:48.57 Xorg
where Xorg is the process whose output to be found. And 7.3 is Xorg's CPU%. I just need the CPU% alone. But here all details of the process including PID are displayed. Is there any way to parse the output?

evo2 12-01-2009 08:26 PM

Quick and dirty with awk:

top -b -n 1  | grep Xorg | awk '{ print $9 }'

ttsdinesh 12-02-2009 12:02 AM

Thank u Evo. I got it...

All times are GMT -5. The time now is 11:04 PM.