← Back to team overview

touch-packages team mailing list archive

[Bug 1468932] [NEW] Values returned by time() are not consistent with value returned by clock_gettime()

 

Public bug reported:

Surprisingly, clock_gettime() bracketed by time() before and after,
returns a value that is outside that interval.


$ taskset 1 time /tmp/testtime
before 1435271727
time   1435271728.0917
after  1435271727
0.57user 0.00system 0:00.57elapsed 100%CPU (0avgtext+0avgdata 464maxresident)k
0inputs+0outputs (0major+157minor)pagefaults 0swaps


$ uname -a
Linux salvador 3.13.0-38-generic #65-Ubuntu SMP Thu Oct 9 11:36:50 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

#include <unistd.h>
#include <time.h>
#include <assert.h>
#include <stdio.h>

int main()
{
    time_t before, after;
    struct timespec ts;

    while (1) {
        before = time(0);
        clock_gettime(CLOCK_REALTIME, &ts);
        after = time(0);

        if (ts.tv_sec < before || after < ts.tv_sec) {
            fprintf(stderr, "before %lu\n", before);
            fprintf(stderr, "time   %lu.09%lu\n", ts.tv_sec, ts.tv_nsec);
            fprintf(stderr, "after  %lu\n", after);
            break;
        }
    }

    return 0;
}

** Affects: eglibc (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to eglibc in Ubuntu.
https://bugs.launchpad.net/bugs/1468932

Title:
  Values returned by time() are not consistent with value returned by
  clock_gettime()

Status in eglibc package in Ubuntu:
  New

Bug description:
  Surprisingly, clock_gettime() bracketed by time() before and after,
  returns a value that is outside that interval.

  
  $ taskset 1 time /tmp/testtime
  before 1435271727
  time   1435271728.0917
  after  1435271727
  0.57user 0.00system 0:00.57elapsed 100%CPU (0avgtext+0avgdata 464maxresident)k
  0inputs+0outputs (0major+157minor)pagefaults 0swaps

  
  $ uname -a
  Linux salvador 3.13.0-38-generic #65-Ubuntu SMP Thu Oct 9 11:36:50 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

  #include <unistd.h>
  #include <time.h>
  #include <assert.h>
  #include <stdio.h>

  int main()
  {
      time_t before, after;
      struct timespec ts;

      while (1) {
          before = time(0);
          clock_gettime(CLOCK_REALTIME, &ts);
          after = time(0);

          if (ts.tv_sec < before || after < ts.tv_sec) {
              fprintf(stderr, "before %lu\n", before);
              fprintf(stderr, "time   %lu.09%lu\n", ts.tv_sec, ts.tv_nsec);
              fprintf(stderr, "after  %lu\n", after);
              break;
          }
      }

      return 0;
  }

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1468932/+subscriptions


Follow ups

References