Check the health and availability of your Linux servers for optimal performance with Site24x7's Linux monitoring tool.
System administrators and Linux experts need a strong understanding of the command line, including the various important commands that help them audit systems. One such command is
uptime is a metric that measures system reliability and stability. It’s represented as the percentage of time that a system remains continuously operational and is available to use. If a system's uptime is high, it indicates that it’s more reliable and stable. Information about uptime is essential, as it helps to monitor how long the system has been running (or up) since the last reboot or shutdown.
Just as it sounds, the
uptime command is used to display how long the system has been running or has remained active. This command retrieves the following information:
You can invoke the
uptime command using the following syntax:
For example, running the
uptime command on a Linux system will display an output similar to:
20:11:37 up 172 days, 22 min, 4 users, load average: 0.23, 0.54, 0.31
In the above output,
20:11:37 is the system current time;
22 min is the system uptime;
4 is the number of active users; and
0.31 are the average system load times for the past one, five, and fifteen-minute durations, respectively.
You can also invoke the uptime command with various options to customize the displayed information using the following syntax:
The following options are used with
uptime to get specific details about the system:
uptime version information and exit
uptime information in pretty format
You can also read the
/proc/uptime file to get the system uptime. /proc is a virtual or pseudo-filesystem, also known as a process information pseudo-filesystem. It contains information about the system and the processes it’s currently running. Files in the /proc directory contain detailed information about kernel, processes, system memory, and hardware configuration.
/proc file system is generated when the system boots, and it’s removed when the system shuts down.
/proc directory contains a file named/uptime that provides the following information:
In a multi-core system, the second value in the
/proc/uptime is the combined idle time of each CPU. For example, if a quad-core CPU is idle for 1 second, then the overall system idle time will be 4 seconds. Consequently, the overall system idle time may be greater than the overall system uptime on multi-core systems.
For example, running the cat
/proc/uptime command on a Linux system regenerates the /proc/uptime file with the following information:
In the above output,
1629.24 is the system uptime and
4171.98 is the system idle time. Clearly, system idle time is greater than system uptime.
There are many commands that display system uptime, such as
top. Unlike the
/proc/uptime file, these commands show the uptime in an attractive format or human-readable form.
So, what’s the use of the
/proc/uptime file if there are already various commands serving the same purpose?
Like any other file in the proc file system, the contents of the /proc/uptime file are generated on the fly. This means that whenever you view the contents of the file, the kernel recalculates the value of uptime and idle time and then displays the result. So, the
file is actually the most accurate source of information for every command that deals with uptime and idle time.
Commands like uptime and w use the output of this file to get uptime measured in seconds and then render them in different formats. Similarly, the top command uses both of the values found in the
/proc/uptime file to calculate the CPU’s idle time percentage.
Another use for the
/proc/uptime file is that you can read it in your custom scripts and use its output for various use cases. For example, if a server needs to be rebooted every month to install the latest security patches and firmware updates, a simple script can be created to continuously read the output of the
/proc/uptime file. As soon as the first value of uptime exceeds 2,592,000 (assuming 30 days in each month), the system will reboot automatically or raise a notification for the system manager.
/proc/uptime can be used to view the uptime of a system. The chart below highlights the major differences between them:
Is a Linux command
Is a pseudo-file in Linux
Displays uptime in human-readable format
Displays uptime by seconds
Does not display the CPU idle time
Displays CPU idle time
Uses the uptime value present in the
The kernel generates this file on the fly when you display the contents of this file
Can be used with various options to display customized or filtered uptime information
Doesn’t provide options to customize or filter uptime information
Can display the current time, boot time, and system load averages
Displays only uptime and idle time information
Linux uptime is an important metric that shows how long the system has been running or how much time has passed since the system last rebooted. It can also be seen as the duration a system can be left unsupervised without crashing.
uptime command is one of the most used commands to determine system uptime because it provides additional system information, like current time, number of active users, and load averages. The
/proc/uptime file displays uptime in seconds (instead of the well-understood time format of hours, minutes, and seconds), which can be challenging to comprehend at first. This is perhaps why uptime isn’t as popular a command, or used as widely.
That said, this file is the most accurate source for the
uptime command as well as others—like top and w—that deal with uptime and idle time. The differences mentioned in this article between
/proc/uptime can help system administrators and Linux experts judge which command is best suited to their given use case.
Monitoring CPU utilization and CPU load is essential for optimizing performance. Learn how to monitor CPU load with common commands, the impact of high CPU load, and how to bring it under control for improved system performance.➤
Learn more on how to optimize and improve the performance of your Linux system in this comprehensive guide on Linux performance optimization.➤
Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.Apply Now