Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-04-2003, 09:40 PM   #1
LQ Newbie
Registered: Jun 2003
Location: Gangavathi, Karnataka(state), INDIA
Distribution: Redhat 7.3
Posts: 28

Rep: Reputation: 15
Question How to get %CPU usage of a process

Hi there,

I need to get %CPU usage of process , I tried following method on Redhat 7.3 Linux 2.4.18-3
1. read /proc/<PID>/stat (utime) entry and save in val1
2. read same /proc/<PID>/stat (utime) entry after 5 seconds and store in val2
3. calculate by using (val2 - val1) / 500 (since jiffies is 1/100 of second).

Does this make any sense.
But when I look at command output of ps -auxw, %CPU usage is about 50-60%(for eg) for daemons (i.e., <PID> above method).
This is a different value than I calculated using above method.

Please let me know
1. if above method is not correct, let me know correct method to calculate %CPU usage of process.
2. Is there any IOCTL calls to process management in Linux where i can get automated value of %CPU usage.

Thanks in Advance.
Old 08-18-2008, 02:52 AM   #2
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Rep: Reputation: 31
run 'top' from the command line - this will tell you all your processes and cpu usage

then use kill (pid) or kill -9 (pid) to kill unwanted processes

(i know this is an old thread, but just wanted to update it in case someone else stumbles across it.)


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
limit cpu % usage for a process student04 Linux - General 15 03-18-2014 08:22 PM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 12:51 PM
process cpu usage vanv101 Fedora 9 06-24-2005 06:53 PM
Limiting a process CPU usage therandomthing Linux - Software 1 06-07-2005 10:00 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 03:17 PM > Forums > Linux Forums > Linux - Newbie

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

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