times(2) sys call bug?

Joakim Tjernlund joakim.tjernlund at transmode.se
Fri Nov 21 02:09:16 EST 2008


Why does the below program end up reporting -1
multiple seconds when times() wrap:

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

main()
{
        unsigned long t1;
        clock_t t2;
        while(1){
                t1 = times(NULL);
                t2 = times(NULL);
                sleep(1);
                printf("unsigned t1:%u, clock_t t2:%d\n", t1, t2);
                if (t2 > 1000)
                        break;
        }
}
and got:

unsigned t1:4294966339, clock_t t2:-957
unsigned t1:4294966439, clock_t t2:-857
unsigned t1:4294966539, clock_t t2:-757
unsigned t1:4294966639, clock_t t2:-657
unsigned t1:4294966739, clock_t t2:-557
unsigned t1:4294967295, clock_t t2:-1
unsigned t1:4294967295, clock_t t2:-1
unsigned t1:4294967295, clock_t t2:-1
unsigned t1:4294967295, clock_t t2:-1
unsigned t1:4294967295, clock_t t2:-1
unsigned t1:43, clock_t t2:43
unsigned t1:143, clock_t t2:143
unsigned t1:243, clock_t t2:243
unsigned t1:343, clock_t t2:343
unsigned t1:443, clock_t t2:443
unsigned t1:543, clock_t t2:543
unsigned t1:643, clock_t t2:643
unsigned t1:743, clock_t t2:743
unsigned t1:843, clock_t t2:843
unsigned t1:943, clock_t t2:943
unsigned t1:1043, clock_t t2:1043





More information about the Linuxppc-dev mailing list