The “ps” Command in Linux [9+ Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The ps command in Linux stands for “Process Status”. It provides a report on the processes running on your machine. By default ps only displays all the processes of the current user in the user’s Terminal. Using options you can select desired processes and discard the default option. In this article, I will demonstrate the usefulness of the ps command in Linux with practical examples.

A. Description

The ps command displays information about selected active processes. By default, the command provides the process ID (PID), the terminal associated with the process (TTY), the cumulated CPU time (TIME), and the executable name (CMD). The BSD-style options add other fields as well. Some of the most common fields are described below.

  • PID: Process ID
  • PPID: Parent process ID
  • TTY: Associated Terminal name
  • TIME: Cumulated CPU time in [DD-]hh:mm:ss format
  • CMD: Executable name
  • COMMAND: Command name (only the executable name).
  • C: Processor utilization
  • STAT: Process state
  • SIZE: Memory size in kilobytes
  • SZ: Size in physical pages
  • STIME: Process start time
  • START: Starting time or date
  • RSS: Resident set size

B. Syntax

The syntax of the ps command in Linux is straightforward. It is the command itself followed by single or multiple options.

ps [options]

C. Options

The ps command comes with a large number of options that are both synonymous and identical. You can mix these options together but it may also result in conflicts. However, I will describe some basic ones here for your convenience. For any further features, you can always look at the man page.

man ps

Useful Options

  • -a ( List processes in BSD format )
  • -A ( Select every process)
  • -e ( Select all processes )
  • -f ( Display processes in full format)
  • -F ( Display processes in extra full format)
  • –forest ( Show process hierarchy in a tree structure)
  • -H ( Show process hierarchy )
  • -p ( Select processes by effective process ID )
  • -u ( Select processes by effective user ID )
  • -x ( List all processes owned by the current user )
NB: The options in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them.

Practical Examples of the “ps” Command in Linux

The ps command, allows you to view process information running on your machine. You can modify the viewing formats using the options provided. Here are some practical examples of the ps command to enhance your experience in Linux.

Example 1: Displaying Processes Running on Current Terminal Session

Using the ps command in Linux without any option, you can display a list of processes running on your current shell. In this example, I will show you the programs currently running on my shell. To do so you may follow the steps below.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps

➌ Now, press the ENTER button.

Output >

In the image below, you can see that I am showing information about the two processes running at the moment on my machine.displaying shell procces information using ps command in linux.


Similar Readings


Example 2: Displaying All the Processes Running on The System Using the “ps” Command in Linux

Using the ps command in Linux you can select every process on the system and display them on your Terminal. Both options -A and -e will provide you with this result. In this example, I will demonstrate listing all the processes on my machine. To do so you may follow the steps below.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command line:

ps -A

Or,

ps -e

➌ Now, hit the ENTER button.

Output >

In the 1st image below, you can see that I am showing a list of every process on my system using option -A.Displaying all the process on system using ps command in linux.In this 2nd image, I have shown the same result as before but using option -e.Dispplaying every process in the system using ps command in linux.

Example 3: Displaying All the Processes Owned by the Current User Using the “ps” Command in Linux

You can display a list of processes owned by the current user with the ps command in Linux using option x. In this example, I will display the processes owned by my machine’s current user. You can do the same by following the given steps.

Steps to Follow >

➊ At first go to your Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps x

➌ Press ENTER

Output >

In the image below, you can see that I am showing information about the processes owned by the current user.Displaying processes owned by current user using ps command in linux.

Example 4: Listing All the Processes in BSD Format Using the “ps” Command in Linux

You can display all the processes on the system in BSD ( Berkeley Software Distribution or Berkeley Standard Distribution ) format using the ps command in Linux. The BSD format provides more information about processes as it shows more fields along with the default four attributes. You will need to combine options a and x to achieve this list. In this example, I will list the processes in BSD format. You can do the same by following the given steps.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command:

ps ax

➌ Now, press the ENTER button.

Output >

In the given image, you can see that I am showing information about the processes on my machine in the BSD format.Displaying process information in BSD format

Example 5: Listing All the Processes in Full Format Using the “ps” Command in Linux

Using the ps command in Linux with option -f or -F you will be able to display the processes on your machine in full format. In this example, I will show you the programs currently running on my system in full form. To do so you may follow the steps below.

Steps to Follow >

➊ Launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps -f

Or,

ps -F

➌ Press the ENTER button.

Output >

In the 1st image below, you can see that I have displayed the processes in full format on my system using option -f.Displaying process information in full format using ps command in linux.In the 2nd image below, you can see that I have displayed the processes in extra full format on my system using option -F.Displaying process information in extra full format using ps command in linux.

Example 6: Listing All the Processes in User-oriented Format Using the “ps” Command in Linux

Using the ps command with option u you can display processes in a user-oriented format. In this example, I will display the processes in my system in a user-oriented format. You can do so by following the given steps.

Steps to Follow >

➊ At first go to your Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps u

➌ Hit the ENTER button.

Output >

In the below image, you can see that I have listed the processes in a user-oriented format.Dispalying processes in user-oriented format using ps command in linux.

Example 7: Displaying Processes by User ID Using the “ps” Command in Linux

You can display a list of processes filtering by user ID with the ps command in Linux. To do so, you will need to type the username after option -u In this example, I will display the processes owned by a user called “anonnya”. You can do the same by following the given steps.

Steps to Follow >

➊ At first, launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps -u anonnya

➌ Now, press ENTER.

Output >

In the image below, you can see that I am showing information about the processes owned “anonnya”.Listing processes of specific user using ps command in linux

Example 8: Displaying Processes by Process ID Using the “ps” Command in Linux

You can list processes filtering by process ID with the ps command in Linux. To do so, you will need to type the process ID after option -p In this example, I will display the process having the ID “1119”. You can do the same by following the given steps.

Steps to Follow >

➊ At first run the Ubuntu Terminal.

➋ Type the following command in the command prompt:

ps -p 1119

➌ Hit ENTER.

Output >

In the image below, you can see that I am showing information about the process with ID “1119”.Listing processes by PID using ps command in linux.

Example 9: Displaying Process Hierarchy Using the “ps” Command in Linux

You will be to display the hierarchy structure of the processes on your machine using the ps command. The H option will indicate the hierarchy with indentation and the –forest option will show output in a tree format. You can follow the steps below to find the hierarchy.

Example A: Getting Process Hierarchy Using the “ps” Command in Linux

To get hierarchy with indentation you can type the following command.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following commands in the command prompt:

ps -H

➌ Now, press the ENTER button.

Output >

In the following image, you can see that I have printed the hierarchy of the current shell processes using the ps command in Linux.Displaying process hierarchy using ps command in linux.

Example B: Getting Process Tree Using the “ps” Command in Linux

To get hierarchy in a tree format you can type the following command.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following commands in the command prompt:

ps --forest

➌ Now, press the ENTER button.

Output >

In the given snapshot, you can see that I have printed the process tree of the current shell processes using the ps command in Linux.Displaying process tree using ps command in linux.

Conclusion

In this article, I have shown you some of the basic applications of the ps command in Linux. You can extract more information about programs running on your system by combining multiple options together. I hope these practical examples will help you engage with Linux and ease your learning of the Command line.


Similar Readings

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment