×

top Command in Linux/Unix with Examples

The 'top' command in Linux is a real-time system monitoring tool that displays information about the running processes and system resource usage. The command provides a dynamic, scrolling view of the process list, and it can be used to monitor the performance of a Linux system and identify any issues that may be causing poor performance.

When you run the 'top' command in a terminal, it will display a list of the processes that are currently running on the system, along with information about their process ID (PID), user, CPU usage, memory usage, and status. The processes are sorted by their CPU usage, with the process that is using the most CPU at the top of the list.

The 'top' command provides a lot of information and can be overwhelming at first, but it is organized into several sections that make it easy to understand. The sections include:

  • The header section: This section displays the current date and time, the system uptime, the number of running processes, and the system load averages.
  • The task area: This section displays a list of the running processes, along with their process ID, user, CPU usage, memory usage, and status.
  • The task summary area: This section displays summary information about the running processes, including the total number of processes, the number of running processes, and the number of sleeping processes.
  • The memory usage area: This section displays summary information about the system's memory usage, including the total amount of memory, the used amount of memory, the free amount of memory, and the shared amount of memory.
  • The swap usage area: This section displays summary information about the system's swap usage, including the total amount of swap, the used amount of swap, and the free amount of swap.
  • The top command also gives a breakdown of the processes and the resources they are consuming

The 'top' command has several command-line options that can be used to customize the display and provide more detailed information about the system and its processes. Some of the most useful options include:

  • '-d' : This option is used to specify the delay between updates. For example, 'top -d 5' will update the display every 5 seconds.
  • '-p' : This option is used to specify the process IDs of the processes that should be displayed. For example, 'top -p 1234' will display only the process with the PID of 1234.
  • '-u' : This option is used to specify the user whose processes should be displayed. For example, 'top -u username' will display only the processes that belong to the user 'username'.
  • '-n' : This option is used to specify the number of iterations that 'top' should run before exiting. For example, 'top -n 5' will run 'top' for 5 iterations.
  • '-h' : This option is used to display the process threads in a hierarchical tree format

You can also press certain key shortcuts while running top command to sort the processes based on different criteria, such as memory usage, process ID, and more.

  • 'M' : sort by memory usage
  • 'P' : sort by CPU usage
  • 'T' : sort by time
  • 'N' : sort by process ID
  • 'R' : reverse the sort order

The 'top' command is a powerful tool that provides real-time information about the running processes and system resource usage. It can be used to monitor the performance of a Linux system, identify any issues that may be causing poor performance, and troubleshoot problems. It is a command that is commonly used by system administrators and developers to monitor the performance of Linux servers and workstations.

One of the key benefits of the 'top' command is that it provides real-time information about the system's resource usage. This makes it an ideal tool for identifying performance issues and troubleshooting problems. For example, if you notice that the CPU usage is consistently high or that the system is running out of memory, you can use the 'top' command to identify which processes are consuming the most resources and take appropriate action to address the issue.

Another benefit of the 'top' command is that it is easy to use and understand. The display is organized into sections that make it easy to understand the information being presented, and the command-line options allow you to customize the display and provide more detailed information about the system and its processes.

The 'top' command can also be used in conjunction with other Linux commands and tools to provide more detailed information about the system and its processes. For example, you can use the 'ps' command to view detailed information about a specific process, or the 'lsof' command to view a list of open files and sockets for a specific process.

In conclusion, the 'top' command is a powerful and versatile system monitoring tool that provides real-time information about the running processes and system resource usage. It is a valuable tool for system administrators and developers, as it can be used to monitor the performance of Linux systems, identify performance issues, and troubleshoot problems. With a little practice, you'll be able to quickly and efficiently use the 'top' command to monitor and optimize the performance of your Linux systems.


Related Topics

tail Command in Linux/Unix with Examples

The "tail" command in Linux (and other Unix-like operating systems) is used to display the last few lines of a file. By default, the tail command will display the last...

4 minutes read.

Linux Distributions

Linux Distributions Linux OS is not like other operating systems. Linux can be modified according to the user’s requirements, and it is very flexible to any change. Linux distributions are often...

4 minutes read.

Linux Admin Tutorial

In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document without relying on meaningful content....

1 minute read.

Linux cd

Linux cd: As in GUI operating systems like Windows 10, we use the mouse to travel to various folders back and forth; similarly, we have the “cd” command in Linux...

4 minutes read.

gzip Command in Linux/Unix with Examples

The gzip command in Linux is used for compressing and decompressing files. It uses the Lempel-Ziv coding (LZ77) algorithm to compress files, which is known for its high compression ratio...

6 minutes read.

Linux Commands with Examples

Linux Commands with Examples All the Linux commands are executed on the terminal provided by the Linux system. This terminal is a command-line interface to implement and display command outputs. Linux...

10 minutes read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

telnet Command in Linux/Unix with Examples

The telnet command in Linux is a command-line utility that allows you to connect to a remote host using the Telnet protocol. Telnet is a network protocol that provides a...

3 minutes read.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

3 minutes read.

Rename Folder in Linux

Rename Folder in Linux In the Linux system, there is not any single dedicated command for renaming the files and directories. Mostly, the mv command is used extensively for the purpose...

3 minutes read.

addr2line Command in Linux with Examples

Use of addr2line Command The addr2line command is used to convert addresses to line numbers and file names. This command uses debugging info to check which line number and file name...

4 minutes read.

rename Command in Linux/Unix with Examples

The rename command in Linux is used to rename multiple files at once, using a specified pattern. The command is also known as rename, ren, and mv. This command is...

3 minutes read.

pwd Command in Linux/Unix with Examples

The "pwd" command in Linux (and other Unix-like operating systems) stands for "print working directory." When executed, it simply displays the current directory (or folder) that the user is currently...

3 minutes read.

ping Command in Linux/Unix with Examples

The "ping" command in Linux (and other Unix-like operating systems) is used to test the connectivity between two networked devices. The "ping" command sends a small packet of data, called...

4 minutes read.

Linux apt-get command

Apt-get is a command-line that helps to handle the packages in Linux. Its major task is to assist in retrieving data and packages from trusted sources for purposes of installation,...

6 minutes read.

Linux Absolute and Relative Path

The concept of the absolute and relative path is very simple. The names “relative path” and “absolute path” give us little understanding of the concept we are learning here. The...

1 minute read.

cut Command in Linux/Unix with Examples

The "cut" command in Linux (and other Unix-like operating systems) is used to remove sections from each line of a file or stream of data. The cut command is often...

3 minutes read.

scp Command in Linux/Unix with Examples

The scp (secure copy) command in Linux is a command-line utility that is used to securely transfer files between two hosts over a network. It is similar to the cp...

4 minutes read.

du Command in Linux/Unix with Examples

The "du" command in Linux (and other Unix-like operating systems) is used to estimate the space used by a file or directory. The du command stands for "disk usage," and...

4 minutes read.

Difference Between Linux and Windows

Linux vs. Windows Here in this tutorial, we are going to discuss several features of Linux and Windows. These features or characteristics help us to come to a conclusion about which...

5 minutes read.