Review your favorite Linux distribution.
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 12-18-2008, 05:40 AM   #1
LQ Newbie
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
Need to write a code in C to find the top 10 process which are utilizing most of the

Hey I have to make a tool to monitor the top 10 processes utilizing the most of the CPU. Need to write a c code.. can any one help from which system file I can read the cpu utilization. tried getting info from proc/<pid>/stat statm status .
Old 12-18-2008, 06:01 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735
Is this a homework assignment?

What happened when you looked at those files in /proc? Do you have the format that describes what they contain?

Have you looked at the "top" command?
Old 12-18-2008, 06:20 AM   #3
Registered: Sep 2004
Posts: 63

Rep: Reputation: 15
you don't need c programming... only a shell command...
ps aux|sort -k3 |tail
Old 12-18-2008, 08:01 AM   #4
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,986

Rep: Reputation: 820Reputation: 820Reputation: 820Reputation: 820Reputation: 820Reputation: 820Reputation: 820
...and as this is an open source OS, you can increase your understanding of how these things are done by looking at the source code of something that does it...

Hope that helps with the homework!
Old 12-19-2008, 12:37 AM   #5
LQ Newbie
Registered: Dec 2008
Posts: 2

Original Poster
Rep: Reputation: 0

Thanks for the response but I need to write a c code for getting the top 10 processes that are using the most cpu..
/proc/<PID>/ folder contains folder like stat statm status which contains a lot of information like utime stime ....
Can I use these info to calculate the cpu usage?


cpu, process, top, utilization

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
How to wait for the process and know if the exit code of the sub process williamhomanchun Linux - General 10 08-11-2008 01:32 PM
How do I find the process details from the C code Manjunath1847 Linux - General 3 07-18-2008 06:45 AM
To find the process that uses the most memory using top nano2 Linux - Server 2 06-12-2008 10:02 AM
top process full path toolshed Linux - Software 7 02-01-2005 04:45 PM
Can't see process with ps or top Lemon Songster Linux - Newbie 0 10-23-2004 08:52 AM

All times are GMT -5. The time now is 02:27 AM.

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