×

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

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.

wc Command in Linux/Unix with Examples

The wc command in Linux is a command-line utility that is used to count the number of lines, words, and characters in a text file or standard input. The name...

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

ps Command in Linux/Unix with Examples

The 'ps' command in Linux is used to display information about the running processes on a system. The command stands for "process status" and it allows you to view details...

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

Linux Commands List

Linux Commands List The Linux systems are filled with commands for several use cases. We have divided these commands into some of the most common implementations for a better understanding of...

2 minutes read.

sed Command in Linux/Unix with Examples

The 'sed' 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...

3 minutes read.

ssh Command in Linux/Unix with Examples

The ssh (Secure Shell) command in Linux is used to remotely access and control another computer or device over a network. It provides a secure and encrypted connection between the...

6 minutes read.

chmod Command in Linux/Unix with Examples

The chmod command in Linux is a command-line utility that is used to change the permissions of files and directories. It stands for "change mode" and it is used to...

4 minutes read.

Linux Tutorial for Beginners

What is Linux? Linux is an open source Operating System like Windows, Android, Mac OS, and iOS. An operating system is a software that enables communication between the user and the...

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

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.

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.

cd Command in Linux/Unix with Examples

The 'cd' command in Linux is used to change the current working directory. The command stands for "change directory" and it is used to navigate the file system on a...

3 minutes read.

Linux Path Completion

Every operating system has some features which make them special. The Linux operating system primarily works on the command line interface, and we do have many features for this CLI....

1 minute read.

df Command in Linux/Unix with Examples

The 'df' command in Linux is used to display the amount of disk space available on the file system. The command reports the amount of disk space used and available...

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

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.

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.

Linux rmdir command

The default use case of the rmdir command in the Linux system is to delete an empty directory. The below screenshot shows how to delete the empty directory. First, we...

1 minute read.