LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem with process time calculation (https://www.linuxquestions.org/questions/linux-newbie-8/problem-with-process-time-calculation-746775/)

aloktiagi 08-11-2009 11:43 AM

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

markush 08-11-2009 11:56 AM

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

tredegar 08-11-2009 12:02 PM

What is this "process" ?

Are you aware of time ?
Code:

time ls -al
real    0m0.035s
user    0m0.010s
sys    0m0.004s


aloktiagi 08-11-2009 12:05 PM

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


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