LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-11-2009, 12:43 PM   #1
aloktiagi
LQ Newbie
 
Registered: Jul 2009
Posts: 20

Rep: Reputation: 0
problem with process time calculation


i'm writing a code to calculate cpu time consumed by a process. i've put the calculations inside a while loop which executes till cpu usage reaches a required value.

i'm using /proc/[pid]/stat (utime and stime field) to find process time. now since the while loop runs infinitely the usage reaches 100% quickly and i'm not able to verify the values.

is there a way to make it gradual increase?
also if i use sleep() in the loop the the process cpu times in /proc/[pid]/stat become zero

please help!!!
thanks
 
Old 08-11-2009, 12:56 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
There is a utility "time".
Quote:
time yourprocess
will show you the time used by yourprocess. If this is not what you're looking for, I'd recommend to download the sources of the time-utility and study this.

Markus
 
Old 08-11-2009, 01:02 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
What is this "process" ?

Are you aware of time ?
Code:
time ls -al
real    0m0.035s
user    0m0.010s
sys     0m0.004s

Last edited by tredegar; 08-11-2009 at 01:02 PM. Reason: I type too slowly!
 
Old 08-11-2009, 01:05 PM   #4
aloktiagi
LQ Newbie
 
Registered: Jul 2009
Posts: 20

Original Poster
Rep: Reputation: 0
if i use time command in my loop will it give real time cpu usage, since i need to check if a particular cpu% is reached.

or will it give the percentage only at the end.

thanks
 
  


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 do i get the values for the user time and system time for a process. aloktiagi Linux - Newbie 3 08-04-2009 07:55 PM
Adaptive ping round-trip time calculation vino87 Linux - Networking 0 07-01-2009 03:58 AM
Process Time ancys Programming 6 08-10-2006 04:14 AM
Time source for fps calculation addy86 Programming 1 09-05-2005 05:16 PM
Time of a process? AquamaN Programming 1 09-22-2003 03:46 AM


All times are GMT -5. The time now is 02:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration