htop:uptime(!)

Linux / Command line

3Way Solutions Image

Nicolas Sugino

Performing a routine check on a client's equipment, I noticed something that had not caught my attention until now...

By opening our beloved and user-friendly htop 

 

3Way Solutions Image

In the image we can see that together with the no small sum of 322 days of uptime we have a (!). This seems to have always been there, but I never paid attention to it. When I did a little research on what it is, I came to the htop code where we can see:

static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
   int totalseconds = Platform_getUptime();
   if (totalseconds == -1) {
      snprintf(buffer, len, "(unknown)");
      return;
   }
   int seconds = totalseconds % 60;
   int minutes = (totalseconds/60) % 60;
   int hours = (totalseconds/3600) % 24;
   int days = (totalseconds/86400);
   this->values[0] = days;
   if (days > this->total) {
      this->total = days;
   }
   char daysbuf[15];
   if (days > 100) {
      snprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
   } else if (days > 1) {
      snprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
   } else if (days == 1) {
      snprintf(daysbuf, sizeof(daysbuf), "1 day, ");
   } else {
      daysbuf[0] = '\0';
   }
   snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
}

And there we realize that it was only the htop congratulating us(?) for having surpassed the milestone of 100 days of uptime 😛

Discover more from 3Way Solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading