How to Monitor System Activity in Linux | top Command - GeeksforGeeks (2024)

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

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (1)

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.

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (2)

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.

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (3)

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.

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (4)

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.

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (5)How to Monitor System Activity in Linux | top Command - GeeksforGeeks (6)

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.

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (7)

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 

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (8) 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.



everythingispossible

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (10)

Improve

Previous Article

How to List Running Processes in Linux | ps Command

Next Article

How to Kill a Process in Linux | Kill Command

Please Login to comment...

How to Monitor System Activity in Linux | top Command - GeeksforGeeks (2024)
Top Articles
Why Investing In Uniswap A Good Option
MouseSavers Frequently Asked Questions - MouseSavers.com
Section 4Rs Dodger Stadium
Riverrun Rv Park Middletown Photos
Mackenzie Rosman Leaked
Alan Miller Jewelers Oregon Ohio
Lexington Herald-Leader from Lexington, Kentucky
Stl Craiglist
سریال رویای شیرین جوانی قسمت 338
City Of Spokane Code Enforcement
Blue Ridge Now Mugshots Hendersonville Nc
Bros Movie Wiki
Bjork & Zhulkie Funeral Home Obituaries
Wisconsin Women's Volleyball Team Leaked Pictures
Swedestats
Air Quality Index Endicott Ny
Xfinity Cup Race Today
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
2011 Hyundai Sonata 2 4 Serpentine Belt Diagram
Orange Park Dog Racing Results
Lcsc Skyward
Craigslist Auburn Al
The Monitor Recent Obituaries: All Of The Monitor's Recent Obituaries
Swgoh Boba Fett Counter
Persona 4 Golden Taotie Fusion Calculator
How to Use Craigslist (with Pictures) - wikiHow
Housing Assistance Rental Assistance Program RAP
Wake County Court Records | NorthCarolinaCourtRecords.us
Flaky Fish Meat Rdr2
Los Amigos Taquería Kalona Menu
Boondock Eddie's Menu
Luciipurrrr_
404-459-1280
Mp4Mania.net1
Tenant Vs. Occupant: Is There Really A Difference Between Them?
PA lawmakers push to restore Medicaid dental benefits for adults
O'reilly's Palmyra Missouri
Todd Gutner Salary
Gotrax Scooter Error Code E2
Silicone Spray Advance Auto
Tinfoil Unable To Start Software 2022
How to Install JDownloader 2 on Your Synology NAS
War Room Pandemic Rumble
Tommy Bahama Restaurant Bar & Store The Woodlands Menu
Hawkview Retreat Pa Cost
Vagicaine Walgreens
Argus Leader Obits Today
Colin Donnell Lpsg
Grand Park Baseball Tournaments
Every Type of Sentinel in the Marvel Universe
Join MileSplit to get access to the latest news, films, and events!
Mytmoclaim Tracking
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 6685

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.