LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-09-2007, 07:37 AM   #1
hamedrafi
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Rep: Reputation: 0
process cpu usage


Hi,

I'm creating a multi-agent program, in which I have to know the exact
cpu usage of my child processes.

in windows there is a function named "getProcessTimes(int pid);",
is there any appropriate linux alternative function that returns the amount
of instructions executed by a process or amount of time used by the child
process, from the process birth until now.

thank you in advance for your help.
 
Old 06-09-2007, 07:59 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
First, keep track of all your children's process ID's by noting what the fork() function returns. Then, for each process ID (567, say), read the file [/B]/proc/567/stat[/B]. Two of the numbers returned are exactly what you want. For information on the numbers you get back, do this at the command prompt:

Code:
man 5 proc
Hope this helps.
 
Old 06-10-2007, 03:45 AM   #3
hamedrafi
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Original Poster
Rep: Reputation: 0
process cpu usage

Hi,
Thank you for reply,
but the thing is, the utime, and stime,
do not change very often. These two change every 2 3 seconds
and n my experiment they increment one step each time.
Also is there any faster way to avoid reading the file each
time I want to know the process times?

Thank you.
 
Old 06-11-2007, 07:34 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
I'm not aware of any better solution. Sorry.
 
Old 06-11-2007, 10:53 AM   #5
entz
Member
 
Registered: Mar 2007
Location: Milky Way , Planet Earth!
Distribution: Opensuse
Posts: 453
Blog Entries: 3

Rep: Reputation: 40
Alright , so you need to figure out how much cpu power each of ur child proc's is consuming , hmmm.
not that I'm sure about that but I guess you could eventually calculate that yourself by measuring how much time each process has been taking (between two points in your code , or so)

I'm going to assume that each of your processes runs an infinite loop of some sorts , then you could insert cputick counting functions at the start and end of the iteration (a time counter if ya know what I mean) , then when you know how much time each iteration of each process has taken you probably can find out the cpu usage of each one by dividing the overall cpu usage by the process specific time consumption...etc

Hope that gets you somewhere,

Regards
 
Old 06-11-2007, 06:32 PM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,401

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
It may help if you re-state the problem, so that you can come up with a metric that better answers your question or better assists you in making your decision, whatever it is.

"The CPU load of a process" is actually a fairly abstract number: it depends upon the nature of the machine, the nature of the workload presented by this application, and the "ambient load," which is the workload presented by all the other processes that are running at the same time. As a result, therefore, it's probably not too useful.

A much better metric would be some sort of metering or counter that the process generates for itself, and which is somehow meaningfully related to the work that this process is designed to do. For example, the number of requests completed per-second, or the ratio of the total application workload that was completed by this particular process. A still better metric might consider the totals of the various kinds of wait-time that are being experienced by the requests ... or by some random sample of those requests.
 
  


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
How to get %CPU usage of a process devershetty Linux - Newbie 1 08-18-2008 01:52 AM
How to get %CPU usage of a process devershetty Linux - Newbie 13 08-16-2008 11:51 AM
How to get %CPU usage of a process romydmisc Linux - Newbie 2 05-24-2006 01:02 PM
process cpu usage vanv101 Fedora 9 06-24-2005 05:53 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 02:17 PM


All times are GMT -5. The time now is 07:24 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration