How to Track System Activity with “top” Command on Linux CentOS (5/6) and RHEL (5/6)

In server administration, it’s crucial to have a comprehensive understanding of your system’s activity. This knowledge allows you to optimize performance, troubleshoot issues, and ensure the smooth operation of your web server.

One of the most effective tools for this purpose is the top command, a utility that provides a dynamic, real-time view of a running system. It displays system summary information as well as a list of tasks currently managed by the Linux kernel.

This guide will walk you through the usage of the top command on CentOS 5/CentOS 6/RHEL 5/ RHEL 6 servers.

For a more in-depth understanding of web server types, you may want to explore our articles on Apache, Nginx, and LiteSpeed. Understanding the type of server you’re working with can greatly enhance your ability to optimize and troubleshoot it.

Using the `top` Command

The top command is a utility that allows you to monitor system activity interactively. When you run top from a shell window, it displays all active processes and updates the screen in real time. This is particularly useful for keeping track of system activity and optimizing system performance.

To display the top command on RHEL 6, you would use the following command:

[root@rhel6 ~]# top

This will display a variety of information, including the total number of tasks, the number of running tasks, CPU usage, memory usage, and a list of all active processes.

[root@rhel6 ~]# top
top - 18:54:19 up 13:29,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:  93 total,   1 running,  90 sleeping,   2 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
Mem:   1031320k total,   225804k used,   805516k free,    31120k buffers
Swap:  2064376k total,        0k used,  2064376k free,   116716k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1375 root      20   0 97768 9796 5768 S  0.3  0.9   0:03.43 httpd
 3974 root      20   0  2632 1076  868 R  0.3  0.1   0:00.08 top
    1 root      20   0  2828 1392 1196 S  0.0  0.1   0:01.81 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    6 root      20   0     0    0    0 S  0.0  0.0   0:00.25 events/0
    7 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cpuset
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 sync_supers
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 bdi-default
   14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0
   15 root      20   0     0    0    0 S  0.0  0.0   0:00.02 kblockd/0
   16 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify
   18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_hotplug
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ata/0
   20 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata_aux
   21 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksuspend_usbd
   22 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khubd
   23 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kseriod
   25 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd
   26 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kswapd0
   27 root      25   5     0    0    0 S  0.0  0.0   0:00.00 ksmd
   28 root      20   0     0    0    0 S  0.0  0.0   0:00.00 aio/0
   29 root      20   0     0    0    0 S  0.0  0.0   0:00.00 crypto/0
   34 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pciehpd
   36 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kpsmoused
   37 root      20   0     0    0    0 S  0.0  0.0   0:00.00 usbhid_resumer
   67 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kstriped
  267 root      20   0     0    0    0 S  0.0  0.0   0:00.00 scsi_eh_0
  268 root      20   0     0    0    0 S  0.0  0.0   0:00.00 scsi_eh_1
  279 root      20   0     0    0    0 S  0.0  0.0   0:00.20 mpt_poll_0

Adjusting the Update Interval

By default, top will update its screen every second. However, you can change this interval by using the d option followed by the number of seconds you want as the new interval. For example, to update the screen every 5 seconds, you would use the following command:

[root@rhel6 ~]# top d 5
[root@rhel6 ~]# top d 5
top - 18:56:51 up 13:32,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:  94 total,   1 running,  90 sleeping,   3 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.7%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1031320k total,   226064k used,   805256k free,    31136k buffers
Swap:  2064376k total,        0k used,  2064376k free,   116716k cached

To update the screen every 10 seconds, you would use:

[root@rhel6 ~]# top d 10
[root@rhel6 ~]# top d 10
top - 18:57:21 up 13:32,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:  95 total,   1 running,  90 sleeping,   4 stopped,   0 zombie
Cpu(s):  0.0%us,  0.1%sy,  0.0%ni, 99.7%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1031320k total,   226448k used,   804872k free,    31144k buffers
Swap:  2064376k total,        0k used,  2064376k free,   116716k cached

Updating the screen at an interval of 5 to 20 seconds is often more useful than the default setting of 1 second. This is because when top updates every second, it often lists itself in its own output as the main resource consumer.

See also  How to Install PHP 5.3 on CentOS 5.9

Getting Help

If you need help while using top, you can press the h key while top is running to display a help screen.

  Z,B,E,e   Global: 'Z' colors; 'B' bold; 'E'/'e' summary/task memory scale
  l,t,m     Toggle Summary: 'l' load avg; 't' task/cpu stats; 'm' memory info
  0,1,2,3,I Toggle: '0' zeros; '1/2/3' cpus or numa node views; 'I' Irix mode
  f,F,X     Fields: 'f'/'F' add/remove/order/sort; 'X' increase fixed-width

  L,&,<,> . Locate: 'L'/'&' find/again; Move sort column: '<'/'>' left/right
  R,H,V,J . Toggle: 'R' Sort; 'H' Threads; 'V' Forest view; 'J' Num justify
  c,i,S,j . Toggle: 'c' Cmd name/line; 'i' Idle; 'S' Time; 'j' Str justify
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u,U,o,O . Filter by: 'u'/'U' effective/any user; 'o'/'O' other criteria
  n,#,^O  . Set: 'n'/'#' max tasks displayed; Show: Ctrl+'O' other filter(s)
  C,...   . Toggle scroll coordinates msg for: up,down,left,right,home,end

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W,Y       Write configuration file 'W'; Inspect other output 'Y'
  q         Quit

Commands Mentioned

  • top – Displays real-time system activity
  • top -d [seconds] – Changes the update interval of `top`

Conclusion

The top command is a powerful tool for server administrators, providing a real-time view of system activity and allowing for the optimization of system performance. By understanding how to use this command and adjust its settings, you can gain a comprehensive understanding of your server’s activity.

This knowledge is crucial for troubleshooting issues, optimizing performance, and ensuring the smooth operation of your server. Whether you’re working with a dedicated server, a VPS server, cloud hosting, or shared hosting, mastering the top command is a valuable skill for any webmaster or website administrator.

Remember, the key to effective server administration is not just about knowing the right commands, but understanding how to interpret the data they provide. With the top command, you have a powerful tool at your disposal to monitor, analyze, and optimize your server’s performance.

Happy server managing!

FAQ

  1. What is the `top` command used for?

    The `top` command is used to monitor system activity interactively. It provides a dynamic, real-time view of a running system, displaying system summary information and a list of tasks currently managed by the Linux kernel. This is particularly useful for keeping track of system activity and optimizing system performance.

  2. How can I change the update interval of the `top` command?

    You can change the update interval of the `top` command by using the `d` option followed by the number of seconds you want as the new interval. For example, `top -d 5` will update the screen every 5 seconds.

  3. Why is it recommended to change the update interval of the `top` command?

    Changing the update interval of the `top` command can prevent it from listing itself in its own output as the main resource consumer, which often happens when `top` updates every second (the default setting). Updating the screen at an interval of 5 to 20 seconds can provide a more useful view of system activity.

  4. What information does the `top` command display?

    The `top` command displays a variety of information, including the total number of tasks, the number of running tasks, CPU usage, memory usage, and a list of all active processes. This information is updated in real time (or at the interval specified with the `d` option).

  5. How can I get help while using the `top` command?

    If you need help while using the `top` command, you can press the `h` key while `top` is running to display a help screen. This screen provides a summary of the command’s options and how to use them.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *