Re: Re: time(1) incorrect (Re) ... times(3) strange; clock_t == long

Fred Roy (froy@gr.osf.org)
Thu, 29 Feb 96 16:57:41 +0100


Craig >If you were to compile time(1) with "gcc -Wall" you would observe some
Craig >warnings about printf int/long mismatches. Fixing those up in the time
Craig >program made it return proper numbers.

I did it already, it does not change the times(3) behaviour... Consider the
following source code:

/* ----- */
#include <sys/times.h>
#include <unistd.h>
#include <stdio.h>
main() {
struct tms my_tms;
int slept;
long ret1, ret2;

slept=2;
printf("going to sleep %d sec...\n", slept);

ret1= (long)times(&my_tms);
slept=sleep((unsigned int)slept);
ret2= (long)times(&my_tms);

printf("before: times() returned %ld\n", ret1);
printf("after: times() returned %ld\n", ret2);
}
/* ----- */

When compiled on BLADE_0.3 then runned, it outputs (for example):
-----
going to sleep 2 sec...
before: times() returned 825630364
after: times() returned 825630366
-------
fred

P.S.: could somebody compile it on a recent RedHat AXP Linux and tell me if it
behaves the same way ? Thanks a lot.