How to use the ps command in Ubuntu Linux with examples

This brief tutorial shows students and new users how to use the ps command on Ubuntu to list and locate currently running processes.

For example, if you have an application locked up or unresponsive and gobbling up all your CPU time and/or RAM, you can use the ps command to look up the application process and kill the process to restore the system’s normal operation.

For students or new users looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

About the ps command:

The ps command is a command line utility that helps you view details of currently-running processes with options to kill or terminate processes that are not behaving normally.

Syntax:

The syntax is the rule and format of how the ps command can be used. These syntax options can be reordered, but a straight format must be followed.,.

Below is an example syntax of how to use the ps command.

ps [options]

Options:

The command line options are switches or flags that determined how the commands are executed or controlled. they modify the behavior of the commands. they are separated by spaces and followed after the commands.

Below are some options for the ps command:

    optionsReplace command a command you want to look up
  ps  –help listps –help list command option common options you can use with the ps command
  ps –help allps –help all command option gives you all the possible command options you can use with ps
  ps –help miscps –help misc gives you miscellaneous options you can use with the ps command
 ps –help simpleps –help simply provides you basic options you can use with the ps command
–helpDisplay a help message

Examples:

Below are some examples of how to run and use the ps on Ubuntu Linux.

Simply run the ps to invoke it.

Running the ps command without options will display a list of processes started by the account running the command.

Output:
PID TTY          TIME CMD
2658 pts/0    00:00:00 bash
19229 pts/0    00:00:00 ps

These represent the columns.

  • PID: The process ID number of the running process.
  • TTY: The console name the user is logged in at.
  • TIME: The CPU processing time used by the process.
  • CMD: The command name that started the process

For example, if you want to list all processes currently running on the system, even those started by other users, simply run the ps command with the -e or -A option.

Example:

ps -e 

This will list all the processes running, but the list is going to be long. So pipe the command with less to break the list by the screen.

Example:

ps -e | less

You should see something similar to the list below:

Output:
  PID TTY          TIME CMD
    1 ?        00:00:03 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 rcu_gp
    4 ?        00:00:00 rcu_par_gp
    6 ?        00:00:00 kworker/0:0H-kb
    7 ?        00:00:00 kworker/u4:0-ev
    8 ?        00:00:00 mm_percpu_wq
    9 ?        00:00:00 ksoftirqd/0
   10 ?        00:00:00 rcu_sched
   11 ?        00:00:00 migration/0
   12 ?        00:00:00 idle_inject/0
   14 ?        00:00:00 cpuhp/0
   15 ?        00:00:00 cpuhp/1

When you want to know more details of running processes, including displaying their parent processes, simply run the ps command with the options:

Example:

ps -eH | less

This will display processes along with their parents

Output:
 2095 ?        00:00:00     gdm-session-wor
 2119 tty2     00:00:00       gdm-x-session
 2121 tty2     00:00:20         Xorg
 2130 tty2     00:00:00         gnome-session-b
 2267 ?        00:00:00           ssh-agent
 2300 tty2     00:00:46           gnome-shell
 2334 tty2     00:00:00             ibus-daemon
 2338 tty2     00:00:00               ibus-dconf
 2599 tty2     00:00:00               ibus-engine-sim
 2416 tty2     00:00:00           gsd-power

This list all processes using the full-format use the ps command with the -ef option

Example:

ps -ef | less

You should see a similar list as shown below:

Output:
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 12:07 ?        00:00:03 /sbin/init splash
root         2     0  0 12:07 ?        00:00:00 [kthreadd]
root         3     2  0 12:07 ?        00:00:00 [rcu_gp]
root         4     2  0 12:07 ?        00:00:00 [rcu_par_gp]
root         6     2  0 12:07 ?        00:00:00 [kworker/0:0H-kb]
root         7     2  0 12:07 ?        00:00:00 [kworker/u4:0-ev]
root         8     2  0 12:07 ?        00:00:00 [mm_percpu_wq]
root         9     2  0 12:07 ?        00:00:00 [ksoftirqd/0]
root        10     2  0 12:07 ?        00:00:00 [rcu_sched]
root        11     2  0 12:07 ?        00:00:00 [migration/0]
root        12     2  0 12:07 ?        00:00:00 [idle_inject/0]
root        14     2  0 12:07 ?        00:00:00 [cpuhp/0]
root        15     2  0 12:07 ?        00:00:00 [cpuhp/1]
root        16     2  0 12:07 ?        00:00:00 [idle_inject/1]

These represent the column:

  • UID: The process owner user ID.
  • PID: The process ID.
  • PPID: Parent process ID.
  • C: The number of children the process has.
  • STIME: Start time of the process.
  • TTY: The console name of the user who started.
  • TIME: The CPU processing time used.
  • CMD: The command name or process name

Killing a process

To kill a process, simply run the kill followed by the process ID ( PID):

Example:

sudo kill 33345

To kill a process by name, use the kill command followed by the process name:

Example:

sudo pkill firefox

You can also use the killall command to kill all the processes along with their child processes

sudo killall firefox

That’s it!

Congratulations! You have learned how to use the ps command on Ubuntu Linux