Does times() work on SUN's properly ?

sbs at csc.fi sbs at csc.fi
Fri Aug 17 05:04:28 AEST 1990


I have problem on our SUN/3 or SUN/4 that I cannot get correct elapsed
time (real time, wall clock time) from function times(). Following
code works on Cray/UNICOS and Iris-4D (under SYSTEM V):

#include <stdio.h>
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>

time_t init_elapsed_time; /* usually time_t is typedefed to long */
struct tms timebuffer;
/* extern time_t times(); */

void starttime()
/* retrieve (elapsed) time since boot etc. */
{
	init_elapsed_time = times(&timebuffer);
}

void cputime(elapsed,usercpu,systemcpu)
/* retrieve CPU etc times spent after doing something */
float *elapsed,*usercpu,*systemcpu;
{
	*elapsed = (float) (times(&timebuffer)-init_elapsed_time) / HZ;
	*usercpu = (float) timebuffer.tms_utime/HZ;
	*systemcpu = (float) timebuffer.tms_stime/HZ;
	return;
}


main()
{
   float e,u,s;

   starttime(); /* initialize init_elapsed_time (may not be zero!) */


   /* do something */

   cputime(&e,&u,&s);

   /* print times */
}


And I will get that elapsed time (variable e) is equal to zero on our SUNs. 
What is going wrong here (on SUN)?

Please answer me directly (to sbs at csc.fi) or via NEWS .


---------
Sami Saarinen
Centre for Scientific Computing



More information about the Comp.lang.c mailing list