How to check running processes in Linux using ps, top, htop, and atop commands

A process is the execution of a program. It can be launched when opening an application or when issuing a command through the command-line terminal. However, an application can run multiple processes for different tasks. For instance, Google Chrome starts a different process each time a new tab is opened.

A process can be initiated as a foreground or background process. Each Linux process is assigned a unique PID (process identification number).

Occasionally, processes can consume many resources and may need to be terminated. Alternatively, there may be times when you’ll want to change the priority level of a process so that the system can allocate more resources to it. Regardless of the case, all these tasks require you to do the same thing – list the running processes on Linux.

How to check running processes in Linux

To list processes in Linux, use one of the four commands: ps, top, htop, and atop. Ps command provides a static snapshot of all processes, while top and htop sort by CPU usage.

Let’s dive further into each of them.

How to check the running process in Linux using the “ps” command

The ps (process statuses) command produces a snapshot of all running processes. Therefore, unlike the Windows task manager, the results are static.

When this command is used without any additional argument or option, it will return a list of running processes. It’ll also have four crucial columns: the PID, terminal name (TTY), running time (TIME), and the name of the command that launches the process (CMD).

You can use ps aux to get more in-depth information about your running processes. Here’s a breakdown of each argument:

  • a option outputs all running processes of all users in the system.
  • u option provides additional information, like memory and CPU usage percentage, the process state code, and the owner of the processes.
  • x option lists all processes not executed from the terminal. A perfect example of this are daemons, which are system-related processes that run in the background when the system is booted up.

If you want to list Linux processes in a hierarchical view, use the ps -axjf command. In this format, the shell will put child processes under their parent processes.

Aside from those two options, here are some other common examples of the ps commands that list running processes in Linux:

  • ps -u [username] lists all running processes of a certain user.
  • ps -e or ps -A displays active Linux processes in the generic UNIX format.
  • ps -T prints active processes that are executed from the terminal.
  • Ps -C process_name will filter the list by the process name. In addition, this command also shows all child processes of the specified process.

How to check the running process in Linux Using the “top” command

The top command is used to discover resource-hungry processes. This Linux command will sort the list by CPU usage, so the process that consumes the most resources will be placed at the top. It’s also useful to check if a specific process is running.

Unlike the ps command, the output of the top command is updated periodically. That means you’ll see real-time updates for CPU usage and running time. Once the shell returns the list, you can press the following keys to interact with it:

KeysFunctions
kTerminates a process.
MSorts the list by memory usage.
NSorts the list by PID.
rChanges the priority of a process.
hDisplays the help window.
zDisplays running processes in colors.
dChanges the refresh time interval.
cDisplays the absolute path of a process.
CTRL+C;or;qStops the top command.

Keep in mind that the keys above are case-sensitive, so be sure to disable the caps lock.

How to check the running process in Linux using the “htop” command

Both the htop and top commands display the same information when listing your Linux processes. However, the former offers user-friendly features that are great for everyday process management.

The htop command allows you to scroll vertically and horizontally. As such, you can see the complete list of your Linux processes along with their full command lines.

What’s more, the command allows you to use a mouse to select items, terminate processes without inserting their PIDs, and change the priority of multiple processes easily.

Unfortunately, most Linux distributions don’t include this command by default, so you need to install it manually.

If you use Ubuntu, you can install htop by running the following command:

sudo apt-get install htop

Once installed, type htop, and you’ll get a list of all your Linux processes.

Just like the previous command, htop also has several keyboard shortcuts:

KeysFunctions
F9To terminate a process.
F8Increase the priority of a process.
F7Decrease the priority of a process.
F6Sort processes by any column.
F5Display processes in a tree view.
F4Filter the processes by name.
F3Search for a process.
F2Open htop setup.
F1Display the help menu.

How to check the running process in Linux using the “atop” command

The atop command is a tool for monitoring system resources in Linux. It is an ASCII full-screen performance utility that logs and reports the activity of all server processes.

Once it is launched, atop will show the resource usage for the CPU, memory, swap, disks, and network in 10-second intervals. atop will stay active in the background for long-term server analysis (up to 28 days by default).

Some of the advantages include:

  • Accumulates resource usage for all processes and users with the same name.
  • Highlights critical resources in colors (red).
  • Shows resource usage of all processes, including those that are completed or closed.
  • Monitors threads within processes (except for unused ones).
  • Uses netatop kernel mobile to monitor TCP, UDP, and network bandwidth.

You can install the atop command by running either of the following commands:

Ubuntu/Debian

sudo apt install atop

CentOS/RHEL/Fedora

sudo dnf install atop

Once installed, run the atop command to display all the process-level uses of the system’s resources.

Here is the list of available arguments and their descriptions:

CommandDescription
man atopDisplays the atop command manual page.
atop -lDisplays the average-per-second total values.
atop -aDisplays the active processes during the last intervals.
atop -cDisplays the command line per process.
atop -mDisplays the memory-related information.
atop -dDisplays the disk-related information.
atop -nDisplays the network information.
atop -sDisplays the scheduling details.
atop -vDisplays the various info (for example PPID, user, or time).
atop -yDisplays the individual threads.

Once atop is running, press the shortcut keys listed below to sort processes:

KeysFunctions
aSorts in order of the most active resources.
cReverts to sorting by the CPU consumption (default).
dSorts in order of disk activity.
mSorts in order of memory usage.
nSorts in order of network activity.

Conclusion

Knowing how to list running processes in Linux is crucial for managing your server. Using the right command is also important for getting the job done.

Be mindful of what Linux distribution you are using, too, as you may have to use different commands to install htop and atop.

Which of the four commands do you prefer? Share your thoughts in the comment section below.

Author
The author

Domantas G.

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.