in reply to $BASETIME (^T) inaccurate?

I've finally gotten this to do it again, and actually had time to look at it in detail.
The program is started automatically at boot by /etc/rc.local
At startup time, the program now saves in globals:
  AppStrtTime = time();
  AppStrtBasetime = $^T;
  UnixUpAtAppStrt = Unix::Uptime->uptime();

The next afternoon I query the program and get:
  System uptime: (81700) 0d 22:41:40
  Program uptime: (82550) 0d 22:55:50
  UnixUpAtAppStrt: 27
  AppStrtTime: 1684095442
  AppStartBasetime: 1684095441
  time() now: 1684177991
  ^T now: 1684095441

Armed with these numbers, reality check:
  UnixUpAtAppStrt = 27 -- sounds reasonable - boot to Perl app startup took half minute
  AppStrtTime follows within a second of AppStrtBasetime -- seems right as ^T was set when the app started, which would be before the code in the app actually started to execute and perform the time() call
  ^T now -- matches the ^T from startup, it has not changed

With AppStrtTime time, and assuming UnixUpAtAppStrt was correct, the actual system startup time was:
  1684095442 - 27 = 1684095415
Subtracting that from time now():
  1684177991 - 1684095415 = 82576
yet:
  Unix::Uptime->uptime() = 81700
WRONG! This should be 82576.
If it was only a few seconds off, I wouldn't have even noticed, but it's off by 14+ mins in under 24 hours!

Maybe some day I'll have a look at Unix::Uptime, but it may be a while - like years.

Replies are listed 'Best First'.
Re^2: $BASETIME (^T) inaccurate?
by Anonymous Monk on May 18, 2023 at 17:58 UTC
    too bad you didn't investigate the real reason this is happening: NTP.
      I'm really confident that it's not NTP causing the problem. The program sends me txt msgs throughout the day, including the time of day to seconds. I've never seen it appear to be out of whack. Doing a 'date' at the command line also seems accurate.

      Tell me this - if the command line time on the rPi is correct right now, and I do a 'shutdown -r now', when it restarts, would the time be way (15 mins) off?

      I did a vanilla noobs installation - doing a 'ps ax | grep ntp' I do not see NTPD running. This means that NTP is not changing the time under the running program, right? Does linux have some default occasional NTP run that I don't know about?

      Thanks for your thoughts!