zlacker

[parent] [thread] 1 comments
1. mkl+(OP)[view] [source] 2025-01-13 11:46:05
Right, as I said, watch is the wrong tool here. The event in common is the synchronised clocks, or an NTP server.

To see the NTP offsets of a machine you can run something like:

  ntpq -pn
ntpdate -q doesn't seem very consistent to me, even pointing it at a nearby server.

To see the clocks ticking visually you can do something like the following and run it on each machine (assuming they have the same ping).

  #include <time.h>
  #include <sys/time.h>
  #include <stdio.h>
  
  void main() {
      struct timeval tv;
      struct timespec ts;
      ts.tv_sec = 0;
      while(1) {
          gettimeofday(&tv, NULL);
          ts.tv_nsec = 1000000000 - 1000*tv.tv_usec; //number of nanoseconds left in the current second
          nanosleep(&ts, &ts);
          gettimeofday(&tv, NULL);
          printf("%lu.%06lu\n", (unsigned long) tv.tv_sec, (unsigned long) tv.tv_usec);
      }
  }
Note that the sleep and second gettimeofday call take a little time (between 70 and 300 μs for me, but it depends what else is running), so the tick times reported won't be exactly on the second.
replies(1): >>nonran+DD3
2. nonran+DD3[view] [source] 2025-01-14 12:32:00
>>mkl+(OP)
Great detailed answer. I upvoted you.
[go to top]