1. Introduction

Both top and htop are common commands to view and manage processes. However, their interfaces also include general system data such as resource usage, load average, users logged into the system at a given moment, as well as other information.

In this tutorial, we’ll talk about uptime and its presentation in the top and htop commands. First, we discuss what uptime means and ways to check it in Linux. After that, we turn to top and htop for their interpretation of the amount of time the system has been running.

We tested the code in this tutorial on Debian 11 (Bullseye) with GNU Bash 5.1.4. It should work in most POSIX-compliant environments unless otherwise specified.

2. Uptime

Uptime is a measurement of the time a given system has been running since its last boot. Because long-running machines have a reputation for stability, uptimes were more a point of pride than functional data in the past.

Linux provides many ways to check how long the system has been running, i.e., the system uptime. Of course, the main one usually involves the uptime command:

$ uptime
 00:06:56 up 10 days, 10:10,  1 user,  load average: 0.00, 0.00, 0.00

In this case, we see several columns:

  • current system time
  • actual uptime in a human-readable format (here, days, hours, and minutes)
  • number of logged-in users
  • system load

Of these, the uptime data comes from the formatted version of the first column in /proc/uptime:

$ cat /proc/uptime
900600.11 1899514.23

Here, both values are in seconds. The latter represents the cumulative amount of seconds each central processing unit (CPU) core has been idle. This way, we not only get an idea about the time passed after the last boot but also how hard the system has been working since then.

Because the procfs pseudo-filesystem is a general interface, other tools also employ it to show additional data.

3. top and htop Uptime

One tool that leverages the uptime information in its first output line is the top utility:

$ top
top - 00:06:56 up 10 days, 10:10,  1 user,  load average: 0.00
[...]

In this case, we see more or less the same columns as before. Similarly, we can run htop to get uptime data:

$ htop
[...] Uptime: 10 days, 10:10:20 [...]

The only difference here so far is the display of seconds.

However, let’s check what we see for a system that has been running for much longer than 10 days:

$ top
top - 00:10:30 up 101 days, 06:06,  1 user,  load average: 0.00
[...]
$ htop
[...] Uptime: 101 days(!), 06:06:06 [...]

An (!) exclamation point within parentheses is now next to the uptime days in the output of htop but not that of top. In fact, this mark appears under specific conditions, as we can see from line 35 of the UptimeMeter.c file from the htop source code:

[...]
  if (days > 100) {
      xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
   } else if (days > 1) {
      xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days);
   } else if (days == 1) {
      xSnprintf(daysbuf, sizeof(daysbuf), "1 day, ");
   } else {
      daysbuf[0] = '\0';
   }
[...]

Here, we see a basic if-else statement. It checks the value of the days variable that holds the number of full days the system has been up. In each case except the last, the code formats the number. For the first case in particular, when days is > bigger than 100, htop includes (!) in the format.

In a way, this mark is an Easter egg stemming from the coveted longest-running server competition of times past. Since a service provided by a single stand-alone machine is now a rare occurrence, the (!) exclamation point can also be interpreted as a warning that the system might need an update or just a plain reboot.

4. Summary

In this article, we covered the system uptime and its relation to top and htop.

In conclusion, long-running systems were treasured in bygone days, so htop still preserves the (!) mark for an uptime of more than 100 days.