LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 12-18-2008, 06:40 AM   #1
kamaalhassan
LQ Newbie
 
Registered: Dec 2008
Posts: 2
Thanked: 0
Need to write a code in C to find the top 10 process which are utilizing most of the


[Log in to get rid of this advertisement]
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 .
kamaalhassan is offline  
Tag This Post , , , ,
Reply With Quote
Old 12-18-2008, 07:01 AM   #2
pixellany
Moderator
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch
Posts: 13,173
Thanked: 285
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?
pixellany is offline     Reply With Quote


Old 12-18-2008, 07:20 AM   #3
fiomba
Member
 
Registered: Sep 2004
Posts: 63
Thanked: 0
you don't need c programming... only a shell command...
Code:
ps aux|sort -k3 |tail
fiomba is offline     Reply With Quote


Old 12-18-2008, 09:01 AM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 1,885
Thanked: 88
...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!
salasi is offline     Reply With Quote


Old 12-19-2008, 01:37 AM   #5
kamaalhassan
LQ Newbie
 
Registered: Dec 2008
Posts: 2
Thanked: 0

Original Poster
Thanks

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?
kamaalhassan is offline     Reply With Quote



Reply

Bookmarks


Thread Tools

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


All times are GMT -5. The time now is 10:37 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration