LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-29-2009, 07:52 PM   #1
ttsdinesh
LQ Newbie
 
Registered: Jun 2009
Location: Erode,TN,India
Distribution: Ubuntu
Posts: 13

Rep: Reputation: 0
Question 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?
 
Old 11-29-2009, 07:54 PM   #2
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
Code:
top | grep java
 
Old 11-29-2009, 07:54 PM   #3
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 650

Rep: Reputation: 79
add " | grep java > newfilename"
 
Old 11-29-2009, 07:57 PM   #4
ttsdinesh
LQ Newbie
 
Registered: Jun 2009
Location: Erode,TN,India
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Let me try and will get u back Dudes.
 
Old 11-29-2009, 08:34 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

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

Evo2.
 
Old 11-29-2009, 09:12 PM   #6
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
what about
root#top -b -d 5 -p <pid of process>

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

Thanks
 
Old 12-01-2009, 06:52 PM   #7
ttsdinesh
LQ Newbie
 
Registered: Jun 2009
Location: Erode,TN,India
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
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?
 
Old 12-01-2009, 07:26 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Quick and dirty with awk:
Code:
top -b -n 1  | grep Xorg | awk '{ print $9 }'
Evo2.
 
Old 12-01-2009, 11:02 PM   #9
ttsdinesh
LQ Newbie
 
Registered: Jun 2009
Location: Erode,TN,India
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs up

Thank u Evo. I got it...
 
  


Reply

Tags
shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run a shell script on remote client from a server to find all its running process robin singh Linux - Newbie 7 10-03-2008 11:32 AM
shell program, how to find substring plz madhugp Programming 1 12-29-2006 10:43 AM
How to find out whether a process is dead or alive from within a shell script file walwali Linux - Software 2 12-24-2005 01:39 PM
How to find which program/service/process touch the file? Raman_RB Linux - Security 2 11-01-2004 03:16 AM
How to determine whether a PROCESS is running, by a SHELL program? yuzuohong Linux - General 4 01-21-2003 08:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration