Understanding ps Command in Linux

Understanding ps Command in Linux

5 mins read2.9K Views Comment
Updated on Aug 16, 2024 15:47 IST

When working with Linux systems, it’s important to have a good understanding of the processes running on your system. This is where the ps command comes in handy. From viewing all processes to filtering, there are a variety of ways to use the ps command to meet your needs.
In this article, we’ll explore the different options and flags available with the ps command and discuss how to use them to gain insights into how your system is functioning.

2023_04_Understanding-Break-Statement-in-C-55.jpg

Knowing your IP address is crucial for managing and troubleshooting your network connection, so let us dive in and understand the use of ps command in Linux.

We will be covering the following sections:

What is the ps Command in Linux?

The ps command in Linux is a powerful tool that allows you to view information about the processes running on your Linux system. It stands for “process status” and it’s a command that you can use from the command line to get information about the currently running processes.

Explore free Linux courses

To start using the ps command, simply open up a terminal window and type “ps” followed by any options or arguments you want to include. Here are a few examples of how you can use the ps command:

Basic usage of ps Command in Linux


 
Copy code

The system will display a list of every process that is currently running on your system:

2023_04_ps-command-in-linux-1.jpg
  • For each process, a unique identification number, known as the PID, is displayed.
  • The TTY column shows the terminal device that is associated with each process.
  • The TIME column displays the amount of CPU time used by each process.
  • The CMD column shows the executable command that was used to start each process. 

Listing all processes

The -e flag is a variation of the ps command that allows you to display the list of every process running on your Linux system, regardless of whether they are associated with the current user or not.

Let’s open the terminal window and type the following command:


 
Copy code

We will see the following output:

2023_04_ps-command-in-linux-2.jpg

This is the list of all the processes within the system, not just the current ones.

View more details

The ps -e -f command is a variation of the ps command in Linux that allows you to display a list of all the processes running on your Linux system in a more detailed format. It provides a full-process listing that includes information such as the process owner, parent process ID, and start time.

The -f option tells the ps command to display a full-format listing that includes additional details about each process.

Let us open the terminal window and type the following command:


 
Copy code

We will see the following output:

2023_04_ps-command-in-linux-3.jpg

Here are some of the key pieces of information that you will be seeing:

  • UID: The user ID number of the user who started the process.
  • PID: The process ID number that uniquely identifies the process.
  • PPID: The parent process ID number.
  • C: The processor utilization percentage.
  • STIME: The start time of the process.
  • TTY: The terminal associated with the process.
  • TIME: The amount of CPU time used by the process.
  • CMD: The command that was used to start the process.

Simple filtering

The ps -C systemd command is a variation of the ps command that allows you to display a list of all the processes running on your Linux system that are related to the systemd process management system. systemd is a software suite that provides system and service management on modern Linux systems.

The -C systemd option tells the ps command to display information about all processes on the system that are related to the systemd process management system.

Let’s open the terminal window and type the following command:


 
Copy code

We will see the following output:

2023_04_simple-filtering-ps-command.jpg

Here are some of the key pieces of information that you will be seeing:

  • PID: The process ID number that uniquely identifies the process.
  • TTY: The terminal associated with the process.
  • STAT: The current status of the process.
  • TIME: CPU time used by processes.
  • COMMAND: The command that was used to start the process.

By using the -u option, we can search for processes based on the username. Let’s open the terminal window and type the following command:


 
Copy code

We will see the following output:

2023_04_ps-command-2.jpg

The -u root option tells the ps command to display information about all processes on the system that are owned by the root user.

List child processes

There are times when we need to view the created child processes instead of threads. This can be done using the -H option.

The -e option tells the ps command to display information about all processes running on the system. The -H option tells the ps command to display information about all child processes created by each parent process.

Let’s open the terminal window and type the following command:


 
Copy code

We will see the following output:

2023_04_image-100.jpg

In this specific scenario, we can observe a hierarchical view of all the processes on the system. However, we cannot directly apply a filter based on the process ID or name. 

Recommended online courses

Best-suited Linux courses for you

Learn Linux with these high-rated online courses

– / –
3 months
7 K
3 months
– / –
2 months
– / –
1 year
– / –
200 hours
– / –
3 months
– / –
3 months
– / –
2 months
– / –
3 months

Limitations of Using the ps Command in Linux

  • Not all processes may be displayed: The ps command can only display information about processes that are currently running on the system. It may not be able to show information about processes that have already ended or have not yet started.
  • Limited information about system resources: While the ps command can provide information about CPU and memory usage, it may not be able to show information about other system resources like disk usage or network activity.
  • Complexity of output: Depending on the options and flags used with the ps command, the output can be complex and difficult to interpret, especially for new Linux users.
  • Limited filtering options: While the ps command allows you to filter processes based on user, command name, or process ID, it may not always be able to filter processes based on more specific criteria like memory usage or CPU load.
  • Different output formats: Depending on the version of Linux and the options used with the ps command, the output format may differ, which can make it challenging to use the command across different systems.
  • Limited to current user’s processes: By default, the ps command only shows processes that are running under the current user’s account. This means that you may not be able to see information about all processes running on the system unless you have superuser privileges.
How to Install Linux using Virtualbox on Windows?
How to Transfer Files Using SCP Command in Linux
10 Implementations of Rsync Command in Linux

Endnotes

In conclusion, the ps command is a powerful tool that can provide valuable information about the processes running on your Linux system. Whether you’re troubleshooting an issue or just curious about how your system is functioning, the ps command can help you better understand what’s going on under the hood. Using various options and flags with the ps command, you can customize the output to show specific information about the processes running on your system.

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio