Hello Chet, hello Felix, hello all!

> > Bash Version: 5.0
> > Patch Level: 16
> > Release Status: release
> > 
> > Description:
> >         Integer part of $EPOCHREALTIME could increase more than 8000
> > microseconds before $EPOCHSECONDS
> 
> It's the difference between time() and gettimeofday().

I didn't believe it ;-) but running

time_gettimeofday.c:
====================
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
  struct timeval tv;
  time_t t;
  struct timespec sleep;
  sleep.tv_sec = 0;
  sleep.tv_nsec = 1000000;
  for (int i=0; i<1001; i++) {
    gettimeofday(&tv, NULL);
    t = time(NULL);
    printf("%d.%.6d %d %d\n", tv.tv_sec, tv.tv_usec, t, tv.tv_sec-t);
    nanosleep( &sleep, NULL );
  }
  return 0;
}

with 

gcc -o time_gettimeofday time_gettimeofday.c && ./time_gettimeofday |
  egrep '\.(00|99)

shows it is right...

Thanks and best regards,

Martin

Reply via email to