The Wayback Machine - https://web.archive.org/web/20240927022814/https://www.geeksforgeeks.org/top-command-in-linux-with-examples/
Open In App

How to Monitor System Activity in Linux | top Command

Last Updated : 12 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it will open an interactive command mode where the top half portion will contain the statistics of processes and resource usage. And Lower half contains a list of the currently running processes. Pressing q will simply exit the command mode.

Check your Version of top

The top -v command is used to display the version information of the top command itself. It shows details such as the version number and possibly other relevant information about the top command’s build or configuration. This can be useful for checking the version to ensure compatibility or to verify if specific features or bug fixes are included in the version being used.

top -v

version

How to Monitor System Activity in Linux Using `top` Command

One of the strengths of the top command is its ability to dynamically update the displayed information at regular intervals. This real-time monitoring capability enables users to observe changes in system activity, identify spikes in resource usage, and quickly respond to performance issues.

To launch the top command, open a terminal window and simply type:

top

This will display a continuously updating screen showing various system metrics. By default, processes are sorted by CPU usage in descending order, with the most resource-intensive processes listed at the top.

Monitor system activity in linux using top command

Monitor system activity in linux using top command

Here,

  • PID: Shows task’s unique process id.
  • PR: The process’s priority. The lower the number, the higher the priority.
  • VIRT: Total virtual memory used by the task.
  • USER: User name of owner of task.
  • %CPU: Represents the CPU usage.
  • TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
  • SHR: Represents the Shared Memory size (kb) used by a task.
  • NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
  • %MEM: Shows the Memory usage of task.
  • RES: How much physical RAM the process is using, measured in kilobytes.
  • COMMAND: The name of the command that started the process.

Uptime

When you first open the top command, the initial line, often referred to as the header or summary line, displays information similar to what you see when you use the uptime command. It shows:

  1. System Time: The current time on the system.
  2. Uptime: How long the system has been running since the last boot.
  3. Users: The number of users currently logged into the system.
  4. Load Average: This is shown in three numbers separated by commas. These numbers represent the average number of processes waiting for CPU time over the last 1 minute, 5 minutes, and 15 minutes, respectively. A value of 1.0 means the system’s CPU is fully utilized; higher values indicate potential overloading.

Tasks

  • Tasks: This section provides an overview of the total number of processes currently managed by the system.
  • total: Indicates the total count of processes currently being tracked by the system.
  • running: Represents the number of processes currently actively using CPU time.
  • sleeping: Refers to processes that are currently idle and waiting for a signal to wake up.
  • stopped: Denotes processes that have been manually stopped, typically through a signal.
  • zombie: Indicates processes that have completed execution but still have an entry in the process table.

%Cpu(s)

The %Cpu(s) line in the top command provides information about CPU usage and statistics on a Linux system. It typically includes:

  • us: Percentage of CPU time spent running user processes.
  • sy: Percentage of CPU time spent running kernel (system) processes.
  • ni: Percentage of CPU time spent running processes with a nice value (priority adjusted).
  • id: Percentage of CPU time spent idle (no work being done).
  • wa: Percentage of CPU time spent waiting for I/O operations to complete.
  • hi: Percentage of CPU time spent servicing hardware interrupts.
  • si: Percentage of CPU time spent servicing software interrupts.
  • st: Percentage of CPU time stolen from this virtual machine by the hypervisor (if virtualized).

MiB Memory

The “MiB Memory” line in the top command provides information about memory usage and statistics on a Linux system. It typically includes:

  • total: Total amount of physical memory (RAM) available in MiB.
  • used: Amount of RAM currently in use by processes and the kernel.
  • free: Amount of RAM not being used at all.
  • buff/cache: Amount of memory used for buffering data and caching filesystems.
  • available: Estimate of how much memory is available for starting new applications without swapping.

MiB Swap

The “MiB Swap” line in the top command provides information about swap usage and statistics on a Linux system. It typically includes:

  • total: Total amount of swap space available in MiB.
  • used: Amount of swap space currently in use.
  • free: Amount of swap space that is not being used.
  • cached: Amount of swap space used for caching swap pages.

Color and Highlighting

In the top command, using the z key toggles color and highlighting of the process list. This feature enhances visibility by color-coding different aspects of the processes, such as CPU usage, memory consumption, and process states (running, sleeping, etc.). It helps users quickly identify resource-intensive processes or anomalies in system behavior.

Color and Highlighting

Only See Active Tasks

In the top command, pressing i (lowercase “i”) toggles the display to show only active tasks. This means top will hide all idle processes (those with zero CPU usage) from the process list, focusing the display only on processes currently consuming CPU resources. This feature is particularly useful for monitoring system activity and identifying processes that are actively using CPU time.

Kill a Process with top

In the top command, you can kill a process using the k key followed by entering the PID (Process ID) of the process you want to terminate. Here’s how you can do it:

  1. Start top by typing top in your terminal.
  2. Locate the process you want to kill using the arrow keys to navigate through the process list.
  3. Note down the PID (Process ID) of the process.
  4. Press k on your keyboard.
  5. Enter the PID of the process you want to kill and press Enter.
  6. Confirm the action if prompted.

Kill a Process with topconfirm

Alternative Display Mode

In the top command, pressing the A key toggles the alternative display mode. This mode rearranges the display to show multiple windows, each focusing on different aspects of system performance, such as CPU usage, memory, and processes. It provides a more comprehensive and detailed view of system activity, making it easier to monitor various metrics simultaneously.

Alternative Display Mode

Examples on How to monitor system activity in Linux Using `top` Command

1) Exit Top Command After Specific repetition:

Top output keep refreshing until you press ‘q‘. With below command top command will automatically exit after 10 number of repetition.

top -n 10

2) Display Specific User Process

top -u paras

3) Highlight Running Process in Top: Press ‘z‘ option in running top command will display running process in color which may help you to identified running process easily

4) Shows Absolute Path of Processes: Press ‘c‘ option in running top command, it will display absolute path of running pro

5) Kill running process: You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without exiting from top window as shown below.

6) Sort by CPU Utilisation: Press (Shift+P) to sort processes as per CPU utilization.

7) Shows top command syntax:

top -h 

top -h 8) Batch Mode: Send output from top to file or any other programs.

top -b

9) Secure Mode: Use top in Secure mode.

top -s

10) Command Line: The below command starts top with last closed state.

Top -c

11) Delay time: It tells delay time between screen updates.

Top -d seconds.tenths

Comprehensive System Monitoring with Glances on Linux

Glances in Linux is a system monitoring tool that provides:

  1. Overview Dashboard: Displays real-time statistics on CPU, memory, disk, network, and processes.
  2. Process Table: Lists detailed information about running processes, including CPU and memory usage.
  3. Alerts and Notifications: Alerts users about critical system metrics exceeding predefined thresholds.
  4. Plugins and Extensions: Supports various plugins for additional monitoring capabilities, such as Docker and SNMP.
  5. Interactive UI: Offers an interactive command-line interface or a web-based interface for monitoring multiple systems remotely.

Are There Alternatives to Top?

  • htop: An interactive and visually appealing process viewer with color-coding, easy navigation, and process management features.
  • Glances: A cross-platform monitoring tool that provides a comprehensive view of system performance, including CPU, memory, disk I/O, and network usage.
  • nmon: A performance monitoring tool designed for AIX and Linux systems, offering detailed statistics and a user-friendly interface.
  • atop: An advanced system and process monitor that provides detailed resource consumption for both current and historical data, including CPU, memory, disk, and network usage.
  • dstat: A versatile resource statistics tool that combines the functionality of vmstat, iostat, netstat, and ifstat into a single command, offering real-time performance monitoring.
  • sar: Part of the sysstat package, it collects and reports on various system activity statistics, including CPU, memory, and I/O usage, with the ability to save data for historical analysis.

Conclusion

In this article we discussed the top command which is an essential tool for Linux users and system administrators, offering real-time insights into system processes and resource usage. Its dynamic interface, interactive commands, and customization options make it a powerful tool for monitoring and troubleshooting. From sorting processes and killing tasks to specific user monitoring, the top command provides a concise yet comprehensive view of system health, enabling users to maintain optimal performance efficiently.

How to Monitor System Activity in Linux | top Command – FAQs

What is the top command in Linux, and how does it help monitor system activity?

The `top` command is a built-in utility in Linux that provides a real-time, dynamic view of the system’s performance. It displays information about CPU usage, memory usage, running processes, and more, allowing users to monitor and analyze system activity effectively.

How do I interpret the information displayed by the top command?

The information displayed by the `top` command includes columns such as PID, %CPU, %MEM, VIRT, RES, and COMMAND. PID is the process ID, %CPU represents CPU usage, %MEM shows memory usage, VIRT is virtual memory, RES is physical RAM usage, and COMMAND displays the name of the process.

Can I customize the display of the top command to focus on specific processes or users?

Yes, the `top` command is highly customizable. Users can press keys to toggle between different views, sort processes based on various criteria, and filter the display to show processes for a specific user. For example, pressing ‘u’ allows filtering by username.

How can I use the top command to identify and terminate resource-hungry processes?

The `top` command allows users to interactively manage processes. Pressing ‘k’ enables the user to kill a specific process by entering its PID. Sorting processes by CPU or memory usage (with ‘P’ or ‘M’) helps identify resource-intensive tasks that may need attention.

Are there additional advanced features of the top command beyond real-time monitoring?

Yes, the `top` command offers advanced features. Users can run `top` with specific options, such as ‘-n’ to exit after a specific number of repetitions, ‘-u’ to display processes for a specific user, ‘-b’ for batch mode (useful for scripting), and ‘-d’ to set the delay time between screen updates. Understanding these options enhances the utility of the `top` command in diverse scenarios.



Previous Article
Next Article

Similar Reads

Sysmon – Graphical System Activity Monitor for Linux
Sysmon is a graphical system monitor for Linux. It shows the information about the CPU, GPU, Memory, HDD/SDD and network connections. It is similar to the Windows task manager. It is completely written into the python programming language. Sysmon shows the all information in the form of Graphical visualization. There are some features of these tool
2 min read
Logcheck Tool - Monitor Kali Linux System Log Activity
Logcheck is a package or tool to check system log files for security violations and unusual activity, it utilizes the program called logtail remembering the last position is read from the log file. Analyzes security or unusual activity from syslog to monitor Apache log files for errors caused by PHP Scripts. Logcheck is used to detect problems auto
4 min read
SAR command in Linux to monitor system performance
sar (System Activity Report) It can be used to monitor Linux system's resources like CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, file system and more. Linux system Monitoring and analyzing aids in understandi
6 min read
Progress - Tool to monitor progress of basic command in Linux
Progress is a command-line-based tiny tool which is formerly known as a Coreutils Progress Viewer. This tool is written in the C language. This command looks for the Coreutils basic command like cp, mv, dd, tar, gzip, cat, etc. which are currently running on the system and display the percentage of copied data. This tool can also show the estimated
2 min read
How to Monitor Linux Commands Executed by System Users in Real-time?
If you are a Linux system administrator then you would definitely want to monitor the interactive activity of all system users, like monitoring the Linux commands they execute in real-time. In this brief Linux system security article, we will be going to discuss how to monitor all Linux shell commands executed by system users in real-time. Let's se
1 min read
Installing atop Tool To Monitor the System Process in Linux
atop is an ASCII full-screen interactive performance monitor which is kind of similar to the top command to view the load over a Linux system. The job of the most critical hardware resources (from a performance point of view) at the system level, i.e. CPU, memory, disk, and network can be seen. atop enable us to identify which processes are actuall
7 min read
How to Monitor System Usage, Outages and Troubleshoot Linux Servers
As we know that Linux is very reliable and a great system administrator should always know the system's behavior and its utilization at every moment of time. So if an administrator or a user wants to monitor its complete system then they have to do the following Storage Space Utilization Linux provides two commands which are used to inspect storage
5 min read
Using htop to Monitor System Processes on Linux
htop a Linux tool that is used in process-managing and terminal-based system monitoring. It allows real-time monitoring of processes and performs every task to monitor the process in the Linux system. The tool is written in the C programming language by Hisham Muhammad. It displays a complete list of processes running on the system and gives inform
5 min read
saidar Utility - Monitor the Linux Box
Saidar is a curses-based (Curses-based software is software whose user interface is implemented through the curses library) tool for viewing system statistics and monitors the Linux system. It is a command-line based tool as it is run on a terminal. To install saidar on Debian based Linux system run the following command on the terminal: sudo apt-g
3 min read
Monitor and Find Statistics for Linux Processes Using pidstat Tool
Pidstat is a command-line tool and part of sysstat suite to monitor the Linux system. It is used to monitor every individual task currently being managed by the Linux kernel on the Linux system. Features of pistat: It can monitor every task running on the systemIt can also monitor the child's task of any task.It shows the total CPU usage by every t
4 min read
Monitor Linux Daemon, Filesystem, CPU, Network and Files Using Monit
Monit is a utility tool for monitoring & managing processes, files, directories, and filesystems on a Unix System. A superpower or a super ability to start a process if it's not running, restart a process if it isn't responding, and stop a process if it uses high resources, that's what Monit(or) does in layman's terms. Monitoring is basically t
3 min read
How to Install and Use bmon Real Time Bandwidth Monitor in Linux?
Bmon Stands is an open source tool for the bandwidth monitoring tool. bmon is a powerful CLI based network bandwidth monitoring and debugging tool for Unix / Linux systems to capture networking related statistics & present them visually on the command line in a human-friendly way. It captures the traffic usage over all the network interfaces on
4 min read
How to Install and Use Scout_Realtime to Monitor Server and Process Metrics in Linux?
There are numerous free tools on Linux that are used to monitor the Linux system including hardware and software. We all may have already come across some command-line Linux performance monitoring tools such as top, htop, atop, etc. Alike that we come across another tool called Scout Realtime tool which is used for server monitoring, that you can s
2 min read
How to Monitor Processor, Memory, Network Performance using dstat in Linux?
Do you want to run a quick performance test on your Linux machine? You may want to check the dstat command. Dstat is a versatile and efficient command that combines the features of several older tools such as vmstat, netstat, iostat, and ifstat to provide useful insights into Linux system performance. You can analyze virtual memory, network connect
2 min read
How use Nmon and "Java Nmon Analyzer" for Monitor Linux Performance
Nmon or Nigel’s Performance Monitor is a tool that is used for the purpose of monitoring resources on Linux, x86_64, Mainframe, etc. With the help of Nmon, you can monitor CPUs, disks, memory, and a couple of other things. There are two modes of Nmon: Online mode: This is used for the purpose of real-time monitoring. Capture mode: In this, the outp
3 min read
How to Monitor CPU and GPU temperature in Linux
This article will discuss How to Monitor CPU and GPU temperature in Linux. There are several ways to do this here in this article we will discuss a few of them. The utilization of currently running programs or applications has no bearing on the CPU or GPU temperature. Operating sensitive computer parts, such as CPUs, at temperatures over a predeter
4 min read
How to Monitor Linux Server Security with Osquery
An operating system is transformed into a massive database with tables that you may query using SQL-like commands using the open-source security application osquery. With the help of these queries, you can do security audits of the target server, monitor file integrity, and more. You can also examine the firewall's status and settings. It is a cros
3 min read
How to Monitor Access Point Signal Strength with wifi-linux
In today's interconnected world, Wi-Fi has become indispensable for both personal and professional connectivity. However, ensuring a stable and secure Wi-Fi connection requires diligent monitoring of access point signal strength. In this comprehensive guide, we'll explore why monitoring access point signal strength is crucial on Linux systems and h
6 min read
How to Use Glances to Monitor Remote Linux in Web Server Mode?
Glances is a system monitoring tool for Linux machines, it is used to monitor system resources in web server mode or through the web browser. It is an alternative to top and htop monitoring tools. This tool has various features and also provides bits of information on a single screen. Glances is a cross-platform, free and open-source tool for monit
3 min read
Check and Monitor Active GPU in Linux
Monitoring the GPU(Graphics Processing Unit) on a Linux operating system is essential for performance testing, debugging, and ensuring usage. There are many tools for checking and monitoring the GPU activity of various GPUs like Nvidia, AMD, or Intel GPU. This article will teach us about multiple methods to check GPU monitors in the Linux Operating
4 min read
How to Put WiFi Interface into Monitor Mode in Linux?
Before looking into Monitor mode and how to switch your WiFi mode from Managed to Monitor, it’s important to understand how a basic WiFi connection is established. When your system connects to WiFi, it sends packets to the WiFi network, which in turn acknowledges these packets, establishing a connection. Once connected, data packets can be sent to
4 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
Finding System Boot-up Performance Statistics in Linux Using systemd-analyze Command
If your Linux system is taking so much time to boot, and you want to know which process is taking so much time to boot then you are on the right page. We are going to see how to get a complete overview of system boot-up time and which service is taking more time to initialize. We are going to use the systemd-analyze command and subcommands of syste
2 min read
How to Mount File System in Linux | mount Command
All files in a Linux filesystem are arranged in form of a big tree rooted at '/'.These files can be spread out on various devices based on your partition table, initially your parent directory is mounted(i.e attached) to this tree at '/', others can be mounted manually using GUI interface(if available) or using mount command. mount command is used
6 min read
How to Manage System Services in Linux | systemctl Command
Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool for managing services. In this article, we will ex
8 min read
Unmount File System in Linux Using the umount Command
Unmounting a file system is a vital procedure for securely deleting storage devices or rendering system resources accessible. A vital instrument in this procedure is the "umount" command, which enables users to softly unmount mounted devices or partitions. Before beginning the unmounting process, this step ensures data integrity and protects any po
7 min read
Reboot Linux System Command with Examples
Rebooting a Linux system is a fundamental administrative task necessary for applying updates, troubleshooting, or system maintenance. Various commands are available to reboot a Linux system, each with specific options and use cases. This guide explores essential reboot commands such as `reboot`, `shutdown`, and `init`, illustrating their usage with
11 min read
Top Linux Command Line Tips and Tricks
Linux is a great OS that offers multiple options for simplifying tasks. It has everything you need for working more efficiently, whether a command-line or a GUI. However, many people don't know the Linux command line's short tricks and end up being stuck in complex tasks. An interface (text-based) through which you communicate with your system's OS
5 min read
Exodus - Copy Linux Binaries From One Linux System
Exodus is an easy-to-implement program, that is used for bundling dependencies, and also helps to effectively copy Linux ELF binaries from one to another machine securely, and this is very handy when you don't have root access, also if there are issues in the availability of the packages in the Linux distribution, Commonly Server oriented distribut
3 min read