LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell program to find a process load (http://www.linuxquestions.org/questions/linux-newbie-8/shell-program-to-find-a-process-load-772334/)

ttsdinesh 11-29-2009 07: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:
Quote:

TOP
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 07:54 PM

Code:

top | grep java

bret381 11-29-2009 07:54 PM

add " | grep java > newfilename"

ttsdinesh 11-29-2009 07:57 PM

Let me try and will get u back Dudes.

evo2 11-29-2009 08:34 PM

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

Evo2.

vishesh 11-29-2009 09:12 PM

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

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

Thanks

ttsdinesh 12-01-2009 06:52 PM

I tried with
Quote:

top | grep java
. But it prints the entire line
Quote:

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 07:26 PM

Quick and dirty with awk:
Code:

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

ttsdinesh 12-01-2009 11:02 PM

Thank u Evo. I got it...


All times are GMT -5. The time now is 06:23 PM.