check uptime

How to Check Uptime of Service in Linux

Sometimes you may need to check uptime of service or process in Linux. In this article, we will look at how to measure the uptime of system as well as a specific service in Linux. You can use these steps for all Linux distributions.


How to Check Uptime of Service in Linux

There are various tools to check uptime in Linux. We will look at how to check both service as well as system uptime in Linux.


1. Check System Uptime

You can use uptime, w or top command to check system uptime. It will show you stats about your system, since last reboot.


Uptime

Uptime command tells you how long the system has been running. It displays current time, number of hours & minutes your system has been up, number of current users, and load average for past 1, 5, 15 minutes.

$ uptime
04:27:15 up 18:14,  1 user,  load average: 0.00, 0.00, 0.00

If you only want to see how long your system has been up, run uptime -p command.

$ uptime -p
up 18 hours, 15 minutes

If you want to see the last reboot time, use -s options

$ uptime -s
2021-06-25 10:12:55


w

w command also shows information similar to uptime. It also shows current time, how long your system has been up, number of current users, system load for past 1, 5, 15 minutes.

$ w
04:29:47 up 18:16,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/0    223.229.210.84   04:26    0.00s  0.04s  0.00s w


top

top command shows the top processes as per their cpu consumption. It updates dynamically and also shows system uptime & load.

$ top
top - 04:32:32 up 18:19,  1 user,  load average: 0.00, 0.00, 0.00
Tasks: 107 total,   1 running,  68 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1002076 total,    83168 free,   578536 used,   340372 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   237912 avail Mem
PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
  1 root      20   0  159576   7704   5564 S  0.0  0.8   0:04.24 systemd
  2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
...


2. Check Service Uptime

If you want to check status of particular service like apache2, you can use service command as shown. Just mention your service name after service command, followed by status keyword.

$ sudo service apache2 status
 ● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
   Drop-In: /lib/systemd/system/apache2.service.d
            └─apache2-systemd.conf
    Active: active (running) since Fri 2021-06-25 10:13:09 UTC; 18h ago
   Process: 860 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCES
  Main PID: 956 (apache2)
     Tasks: 10 (limit: 1140)
    CGroup: /system.slice/apache2.service
            ├─ 956 /usr/sbin/apache2 -k start
            ├─ 961 /usr/sbin/apache2 -k start
            ├─ 962 /usr/sbin/apache2 -k start

In the above output, you will see Active flag, which shows how long your service has been running. You can also use systemctl command just like service command, to get service status. But in case of systemctl you need to mention status keyword before service name

$ sudo systemctl status apache2
 ● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
   Drop-In: /lib/systemd/system/apache2.service.d
            └─apache2-systemd.conf
    Active: active (running) since Fri 2021-06-25 10:13:09 UTC; 18h ago
   Process: 860 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCES
  Main PID: 956 (apache2)
     Tasks: 10 (limit: 1140)
    CGroup: /system.slice/apache2.service
            ├─ 956 /usr/sbin/apache2 -k start
            ├─ 961 /usr/sbin/apache2 -k start

Please note, the difference in syntax between service and systemctl commands above.

In this article, we have covered different ways to check system uptime as well service uptime.

Also read :

How to Resize Partition in Ubuntu
How to Update Key in Python Dictionary
How to Search Item in List of Dictionaries in Python
How to Remove Multiple Items from List in Python
How to Flatten List of Dictionaries in Python

Leave a Reply

Your email address will not be published.