LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2003, 12:49 PM   #1
Jehos
LQ Newbie
 
Registered: Nov 2003
Posts: 4

Rep: Reputation: 0
CPU Usage


Hi.

Anyone knows how to get what percentaje of the CPU is using a program?

I need to know how much CPU is using my program, and act acordingly depending on the percentaje.

Thankss

Jehos.-
 
Old 11-28-2003, 01:12 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
In the /proc filesystem there are PIDs for each process running. In the directory for each process there is a stat file. The contents look something like this:
Code:
4005 (httpd) S 4004 4004 4004 0 -1 320 348964 160119 44705 52629 152362 
7396 10394 669 9 0 0 0 60487804 19304448 2647 4294967295 134512640 
134790828 3221224128 3221223664 1075297966 0 0 4096 71329387 3222576587 0 0 17 0
In there is all the information that you need. The proc man page details what all the fields are for and the type information.

Hope this helps

Edit: chopped up the code segment to display better

Last edited by crabboy; 11-28-2003 at 01:13 PM.
 
Old 11-28-2003, 01:16 PM   #3
Jehos
LQ Newbie
 
Registered: Nov 2003
Posts: 4

Original Poster
Rep: Reputation: 0
going to check it... thank youuu
 
Old 11-30-2003, 05:46 AM   #4
hiteshmaisheri
Member
 
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231

Rep: Reputation: 30
Just check with the top command ... it will present u with all the details regarding the cpu usage, memory usage, etc and lots of other details
 
  


Reply


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
Get CPU Usage ramicub Programming 3 11-02-2010 04:34 AM
cpu usage bijuhpd Linux - Newbie 4 10-02-2005 10:41 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:28 AM.

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