accounting
Robert Breckinridge Beatie
breck at aimt.UUCP
Wed Mar 9 15:09:32 AEST 1988
In article <1094 at hubcap.UUCP>, hubcap at hubcap.UUCP (Mike Marshall) writes:
> ... I need to
> charge people for CPU time. I see three fields which in themselves,
> or in some combination, might give me a reasonable number to use:
> - ac_utime defined as "user time"
> - ac_stime "system time"
> - ac_etime "elapsed time"
> ... What can you tell me about these fields?
The ac_utime and ac_stime fields are the ones you want to charge for cpu time.
On many systems they store the amount of cpu time, in seconds, spent by the
process in user and system state respectively.
The fields are normally stored in a "pseudo floating point" format. The top
3 bits of the word are the exponent with the bottom 13 bits being the
mantissa.
Here's a snippet of code to translate the fields:
time_t
cvrt(tim)
comp_t tim;
{
unsigned int exponent;
time_t mantissa;
mantissa = tim & 0x1fff;
exponent = tim >> 13;
while(exponent--)
mantissa <<= 3; /* multiply by 8 (base of exponent) */
return mantissa;
}
At least I think this works. It's based on recollection from a program
I whipped up a year ago to read the process accounting file.
One possible problem you might run into is the units of the number stored
in the ac_{s,u}time fields. On some systems the units are seconds and
commands that take less than 1 second of cpu time have 0 stored in the
process accounting file. On other systems the units are 1/CLK_TCK seconds
so to get numbers in seconds, you'll have to divide by CLK_TCK (Whatever
that value might be).
--
Breck Beatie
{uunet,ames!coherent}!aimt!breck
"Sloppy as hell Little Father. You've embarassed me no end."
More information about the Comp.unix.questions
mailing list