Skip to main content

Process Commands

ps Command Examples

The ps command in Linux is used for getting information about running processes. Here are some useful examples of the complicated and extensive ps command.

The ps command in Linux displays running processes on the system. You can get information like process ID (PID) for the processes you or any other user is running on the same Linux system.

The ps command is an extensive tool and has over 80 command options. You can understand its strength and complexity. This is why I will show you some of the most common and useful examples of the ps command in Linux.

Essential usage of ps command in Linux

If you use the ps command without any options in Linux, it will show the running processes in the current shell:


This is the output. I have sent Gedit command in the background this is why it shows three processes otherwise you will normally see just ps and bash.

  PID TTY          TIME CMD
  503 pts/0    00:00:00 gedit
 2053 pts/0    00:00:00 ps
31585 pts/0    00:00:00 bash

In here:

  • PID is the unique process ID of the process
  • TTY is the type of terminal user is logged in to. pts means pseudo terminal
  • TIME gives you how long the process has been running
  • CMD is the command that you run to launch the process

Now, this doesn’t really provide any real, useful information. Let’s see some better examples of the ps command:

1. See all your running process

If you want to see all the processes run by you, you can use the ps command with options x like this:

ps -x

The x option will display all the processes even if they are not associated with current tty (terminal type) or if they don’t have a controlling terminal (like daemons).

The – before option x is optional, but the general Linux convention is to use – before options, so I advise you to keep on following it. It won’t hurt you.

This is what the output looks like. I have truncated the output because it had hundreds of lines:

  503 pts/0    Sl     0:00 gedit
 2245 ?        S      0:00 /usr/bin/ssh-agent -D -a /run/user/1000/keyring/.ssh
 3039 ?        Ss     0:00 /lib/systemd/systemd --user
 3040 ?        S      0:00 (sd-pam)
 3054 ?        SLl    0:01 /usr/bin/gnome-keyring-daemon --daemonize --login
 3059 tty2     Ssl+   0:00 /usr/lib/gdm3/gdm-x-session --run-script env 

The STAT in the above output means Process State Codes. You can find a detailed table in the man page of the ps command.

But you’ll rarely see ps command used with just option x. It is usually accompanied by option u in this manner:

ps -ux

With option u, you’ll have detailed information about each process:

abhishek   503  0.0  0.4 681580 37516 pts/0    Sl   18:09   0:00 gedit
abhishek  2245  0.0  0.0  11300  1496 ?        S    18:37   0:00 /usr/bin/ssh-agent -D -a /run/user/1000/keyring/.ssh
abhishek  3039  0.0  0.0  77344  3508 ?        Ss   10:37   0:00 /lib/systemd/systemd --user
abhishek  3040  0.0  0.0 114632   360 ?        S    10:37   0:00 (sd-pam)
abhishek  3054  0.0  0.1 517104 11512 ?        SLl  10:37   0:01 /usr/bin/gnome-keyring-daemon --daemonize --login

As you can see, now you get the user name, CPU consumption, and memory usage of each process. RSS shows how much memory the process currently has in RAM while VSZ is how much virtual memory the process has in total.

2. See all running processes with ps aux command

You’ll probably see ps -aux or ps aux all the time in Linux tutorials and documentation.

With the added -a option, you can see the running processes by all the users on Linux system.

ps -aux

The command output is the same as ps -ux but now you have processes from other users as well. Thanks to the -u option, you can identify which process belongs to which user.

List all running processes in Linux

3. See all running processes with ps -ef command in Linux

Apart from ps -aux, you can also list all the running processes with -e option. The common practice is to combine it with the option -f to get the full listing of the commands used to run the processes.

ps -ef

Do note that – before e is important; otherwise, it will show a different result. I told you, ps is a messed up, complicated command.

You can also combine the H option to see all the processes in a threaded view with child processes under their parents:

ps -efH

4. See all running processes by a certain user

To get the information about all the processes run by a certain user, you can use the -U option with the user name:

ps -U user_name

For example, I can see all the processes running by the root user like this:

ps -U root
  PID TTY          TIME CMD
    1 ?        00:00:41 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 rcu_gp
    4 ?        00:00:00 rcu_par_gp
    8 ?        00:00:00 mm_percpu_wq
    9 ?        00:00:03 ksoftirqd/0
   10 ?        00:01:22 rcu_sched

5. See all processes run by a group

You can also categorize running processes by group instead of users by providing group name or group id:

ps -G group_name_or_id

You can combine with option f to get the full listing.

6. Get all occurrences and PID of a program

One of the essential use of the ps command is to get the process ID (PID) of a running program. Normally when you are looking to kill a misbehaving program, you search for all the program occurrences, get their PIDs and use the kill command to end the process.

ps -C program__name

For example, if I have to find all running instances of the apt package manager:

ps -C apt
  PID TTY          TIME CMD
11425 pts/1    00:00:00 apt

You can also use grep command to get a similar result.

ps aux | grep program_name

7. Get process information about a PID

Alright! You have a PID but don’t know which process it belongs to. You can use the ps command to find the process information from its PID in this way:

ps -pN

You can use more than one PID by separating them with a comma:

ps -pN1,N2,N3

What else?

As I said earlier, ps is a complicated and extensive command. These were some of the most common ps command examples you’ll need most of the time. If you want more, you can always refer to its man page.

If you have some other useful example of the ps command that you use regularly, why not share it with the rest of us in the comment section?

Abhishek Prakash