HostArmada Web Hosting Knowledge Base

Knowledge is power! Use that power and achieve total and unconditional control over the Web Hosting Services!

The top command.

The top command is an essential monitoring tool for Unix based systems. It is used daily by system administrators around the globe to monitor the processes currently managed by the kernel. What makes it so useful is that it displays the information in real-time. In addition to showing an interactive list of all the currently running processes, it also presents information about the system's CPU usage, Memory usage, and load. In this article, we are going to discuss how to use the command, and we will introduce you to a few of it's most useful flags.

Please access your server over SSH and type in:

top 

The output will be similar to this one:

top - 14:09:19 up 3 days, 18:30, 1 user, load average: 0.29, 0.41, 0.39
Tasks: 169 total, 1 running, 168 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.5 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3880408 total, 417384 free, 1707508 used, 1755516 buff/cache
KiB Swap: 524284 total, 524284 free, 0 used. 1587864 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 818609 root 20 0 160180 2388 1572 R 1.0 0.1 0:00.06 top
      1 root 20 0 43932 4064 2380 S 0.0 0.1 675:04.73 systemd
      2 root 20 0 0 0 0 S 0.0 0.0 0:00.05 [kthreadd]
      3 root 20 0 0 0 0 S 0.0 0.0 0:21.25 [ksoftirqd/0]
      5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H]
      7 root rt 0 0 0 0 S 0.0 0.0 0:01.20 [migration/0]
      8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh]
      9 root 20 0 0 0 0 S 0.0 0.0 5:31.67 [rcu_sched]
     10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [lru-add-drain]

On the upper side of the output, you will see information regarding system uptime, load, CPU utilization, and memory usage. Underneath, you will see a list of all the running processes. On the left side of the process list, you will see the user executing the process along with the PID(process ID), and at the far right side, you can observe the command, script or service that triggered it. Let's explore some useful flags for the command. By default, "top" will refresh the interactive list of processes once every 3 seconds. You may override this using the "d" flag and attach a number that will represent the time-frame in which the list of processes is refreshed.

top d1 

This option will cause the "top" command to refresh the list once every second. To show the absolute path of the scripts or services executing a specific command, please type:

top -c 

The "-c" flag can be combined with the previous one, enabling you to refresh the list once per second. Here is what the output will look like:

[[email protected] ~]# top -c
top - 14:17:07 up 3 days, 18:38, 1 user, load average: 0.29, 0.29, 0.33
Tasks: 173 total, 1 running, 171 sleeping, 0 stopped, 1 zombie
%Cpu(s): 1.5 us, 1.5 sy, 0.5 ni, 96.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3880408 total, 301576 free, 1736516 used, 1842316 buff/cache
KiB Swap: 524284 total, 524284 free, 0 used. 1501976 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
   2321 root 20 0 771960 65120 4636 S 2.6 1.7 46:03.88 /opt/alt/python35/bin/python3 -m im360.run --daemon --pidfile /var/run/imunify360.pid
   4395 root 30 10 367920 57304 3952 S 1.0 1.5 21:51.93 /opt/alt/python27/bin/python2.7 /usr/share/lve-stats/lvestats-server.py start --pidfile /var/run/lvestats.pid
   4270 root 30 10 494520 39828 564 S 0.7 1.0 19:08.52 /opt/alt/python27/bin/python2.7 /usr/share/lve-stats/lvestats-server.py start --pidfile /var/run/lvestats.pid

Lastly, we will talk about the "-u" flag. What it will let you do is monitor the processes in real-time only for a specific user on your Unix system.

top -u  

Again, this flag can be combined with the "d" and "-c" options for a faster or slower renewal of the list and a broader representation of the script/service, which triggered the process.

Was this article useful and on point?

Find out more about HostArmada entire range of optimized Web Hosting Services and take action today on improving your website Loading Speed, Security, and overall Stability!