LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to write a code in C to find the top 10 process which are utilizing most of the (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-write-a-code-in-c-to-find-the-top-10-process-which-are-utilizing-most-of-the-691443/)

kamaalhassan 12-18-2008 05:40 AM

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 .

pixellany 12-18-2008 06:01 AM

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?

fiomba 12-18-2008 06:20 AM

you don't need c programming... only a shell command...
Code:

ps aux|sort -k3 |tail

salasi 12-18-2008 08:01 AM

...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!

kamaalhassan 12-19-2008 12:37 AM

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?


All times are GMT -5. The time now is 07:02 PM.