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

Date:

Share post:

The `top` command is a powerful utility in Linux used to provide a real-time, dynamic view of a system’s performance. It offers a comprehensive summary of system resources and a detailed list of running processes or threads managed by the Linux Kernel. Here’s how you can effectively utilize the `top` command to monitor system activity.

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

 

top

 

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

Understanding `top` Output:

The `top` command provides a wealth of information, including:

PID: Process ID, uniquely identifying each task.

PR: Process priority, with lower numbers indicating higher priority.

VIRT: Total virtual memory utilized by the task.

USER: Username of the task owner.

%CPU: CPU usage percentage by the task.

TIME+: CPU time, displaying hundredths of a second for granularity.

SHR: Shared memory size used by the task.

NI: Nice value of the task, affecting its priority.

%MEM: Memory usage percentage of the task.

RES: Physical RAM consumed by the process, measured in kilobytes.

COMMAND: Command name initiating the process.

Examples of `top` Command Usage:

Exit after Specific Repetition: Use `-n` option to exit `top` command automatically after a defined number of repetitions:

 

top -n 10

 

2. Display Specific User Process: Filter `top` output to show processes of a specific user using the `-u` option:

 

top -u username

 

3. Highlight Running Processes: Press `z` within the `top` command to display running processes in color, aiding in easy identification.

4. Show Absolute Path of Processes: Press `c` within the `top` command to display the absolute path of running processes.

5. Kill Running Process: Terminate a process directly from `top` command by pressing `k` and entering the PID of the process to be killed.

6. Sort by CPU Utilization: Sort processes by CPU usage by pressing `Shift+P`.

7. View Command Syntax: Learn about different options and syntax using `-h` option:

 

top -h

 

8. Batch Mode: Utilize `-b` option to send `top` output to a file or other programs.

 

top -b

 

9. Secure Mode: Run `top` in secure mode using `-s` option.

 

top -s

 

10. Command Line History: Initiate `top` with the last closed state using `-c` option.

 

top -c

 

11. Set Delay Time: Adjust the delay time between screen updates using `-d` option.

 

top -d seconds.tenths

 

Conclusion:

The `top` command is indispensable for Linux users and system administrators, providing real-time insights into system processes and resource utilization. Its dynamic interface, interactive commands, and customizable options make it an invaluable tool for monitoring and troubleshooting system performance effectively. Whether sorting processes, terminating tasks, or filtering by user, `top` offers a concise yet comprehensive view of system health, enabling users to maintain optimal performance effortlessly.

 

Source link

spot_img

Related articles

Nintendo, Sony And Xbox Update “Safer Gaming” Principles

In 2020, the major players in the console space Nintendo, Sony and Xbox announced a "shared commitment to...

Patch Tuesday, January 2026 Edition – Krebs on Security

Microsoft today issued patches to plug at least 113 security holes in its various Windows operating systems and...

Some Motherboard UEFIs Are Injecting Software Into Windows

Following my article about BitLocker encrypting the OS drive on my Asus laptop without my consent, I began...

How to Digitalize Education Fairs and Maximize Impact: The Educoway Case

Organizing education fairs is no small task. From registering participants and managing check-ins to capturing leads for exhibitors,...