*BSD News Article 42956


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.hawaii.edu!ames!haven.umd.edu!news.umbc.edu!eff!news.kei.com!news.mathworks.com!newshost.marcam.com!usc!howland.reston.ans.net!Germany.EU.net!netmbx.de!CNB.CompuNet.DE!zrz.TU-Berlin.DE!cs.tu-berlin.de!engel
From: engel@cs.tu-berlin.de (Christian Engel)
Newsgroups: comp.os.386bsd.questions
Subject: getrusage() question
Date: 18 Feb 1995 11:52:06 GMT
Organization: Technical University of Berlin, Germany
Lines: 49
Message-ID: <3i4n16$8gf@news.cs.tu-berlin.de>
NNTP-Posting-Host: gragra.cs.tu-berlin.de
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

I tried to implement a timer functionality with getrusage() in FreeBSD.
At the beginning, it seemed to work fine.  But then I  used it to measure
the timings of short intervals of about 10ms.  An interesting effect comes
up.  The used user time for this process in microseconds 
(ru_utime.tv_usec) is becoming smaller and there is no increase in the 
ru_utime.tv_sec value.


The table below shows 6 measured values.   The ___D are the deltas  to the
previous value.  The values are in seconds. 

ustime = u_time + s_time


#   ustime    ustimeD    utime    utimeD    stime     stimeD   Ress uDat 
------------------------------------------------------------------------
01 00.052091           00.014883           00.037208           0360 0572 
02 00.054370 00.002279 00.015534 00.000651 00.038836 00.001628 0360 0572
03 00.055225 00.000855 00.013806 -0.001728 00.041419 00.002583 0368 0600 
04 00.055702 00.000477 00.013925 00.000119 00.041777 00.000358 0368 0600
05 00.056168 00.000466 00.014042 00.000117 00.042126 00.000349 0368 0600
06 00.056629 00.000461 00.014157 00.000115 00.042472 00.000346 0368 0600


I found an article in a german computer magazine stating that 
gettimeofday() for SUNOS 4 and Solaris 2 have a higher resolution than
getrusage().  The time(1) command of BSD-4.4 also uses the gettimeofday()
function. 

The article tells more  about the inaccuracy of the timings 
and special
effects of SUN SLCs which sometimes add 10ms to give the user the impression
that time is progressing. By the way, I had a look at the source code
of SUNOS 4 and Sol 2.3.  SunOS is also using gettimeofday() whereas Solaris
uses times().

But beside of that, I do not understand why the value denoting
the so far used time of the process is becoming smaller.

If anyone can explain this effect, please send me a mail.

Thanks in advance,
	Christian

-- 
============================ Christian Engel ==================================
     ***** Graduiertenkolleg Kommunikationsbasierte Systeme *****
	TU Berlin, Sekr. FT-5, Einsteinufer 25, D-10587 Berlin
MAIL: engel@cs.tu-berlin.de  TEL: +49 (30) 314 23810    FAX: +49 (30) 314 22514