×

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

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.

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.

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...

4 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.

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.

chown Command in Linux/Unix with Examples

The 'chown' command in Linux is used to change the ownership of a file or directory. The command stands for "change owner" and it allows you to change the user...

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.

Linux ls

The primary use case of the ls command is to list the content available in the directory. The default directory is the current directory of the user. The below screenshot...

5 minutes read.

rm Command in Linux/Unix with Examples

The "rm" command in Linux (and other Unix-like operating systems) is used to remove files and directories. The "rm" command stands for "remove" and it is used to delete files...

4 minutes read.

cat Command in Linux/Unix with Examples

The cat command in Linux is a command-line utility that is used to display the contents of a text file. It stands for "concatenate" and it is used to view...

4 minutes read.

tar Command in Linux/Unix with Examples

The 'tar' command in Linux is used to create, maintain, and extract files from archive files called tarballs. The command stands for "tape archive" and it allows you to combine...

4 minutes read.

ls Command in Linux/Unix with Examples

The ls command in Linux is a command-line utility that is used to list the files and directories in a directory. It is one of the most basic and commonly...

4 minutes read.

Difference Between Unix and Linux

Unix vs Linux Unix and Linux both have been of great use in changing the world of operating systems. Unix was among the very few operating systems which were programmed for...

4 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.

Linux pwd

The pwd command is used to print or display the name of the working or current directory. Some shells have their own version of the pwd with several features, in...

1 minute read.

curl Command in Linux/Unix with Examples

The 'curl' command in Linux is a command-line tool that allows you to transfer data from or to a server using various protocols, including HTTP, HTTPS, FTP, and many more....

3 minutes read.

awk Command in Linux/Unix with Examples

The 'awk' command in Linux is a powerful text processing tool that allows you to perform various operations on text files, such as searching, replacing, and manipulating text. The command...

4 minutes read.

addgroup Command in Linux with Examples

What is the addgroup command? It is a command in Linux to create a new group using specified command lined and the system’s default values. How to add groups Adding a user group:...

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 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.