Ps Command in Linux with Examples

Ps Command in Linux with Examples

Ps stands for process status and it is one of the commonly used commands in Linux server administration. In this tutorial, we are going to explore some examples of ps command. All commands have been executed on Red Hat Enterprise Linux 9.

Syntax

The general syntax of the command is as follows:

ps [OPTIONS]

Examples

List the processes in current shell

When ps is invoked without any options, it lists the processes running in the current shell.

ps

The output of the command has four columns:

  • PID is process ID.
  • Type of terminal user is logged in to.
  • Time shows the hour, minute, and second, the process has been running.
  • CMD is the command the process is running.

List all processes

To list all processes running on your system, invoke the command with -A or -e option. You would run:

ps -A

List all running processes

You can list all the running processes (even those that are not related to the current shell) by using -ax option as follows:

ps -ax

List all processes in BSD format

To list all running processes in BSD format, you would run the following on the terminal:

ps -aux

Display all processes in long list format

To display all processes in long list format, you would run:

ps -ef

List processes of specific user

You can list the processes of a specific user with -u option followed by the user name. Suppose, you want to list the processes of user ‘karim’ you would run:

ps -u karim

Search process

You can search any process with the help of -C option. Suppose you want to search the process ‘bash’, you would run on the terminal.

ps -C bash

List processes with specific columns

You can use -o option to list processes with specific columns. Suppose you want to see PID and command column of all processes. You would type:

ps -axo pid,cmd

Conclusion

This article has explained the working of ps command in Linux. Keep visiting Linux World for more tutorials.