How to use the ps command in Ubuntu Linux with examples

|

|

This tutorial explains how to use the ‘ps’ command on Ubuntu Linux to manage running processes. Intended for beginners, it covers how to list and locate active processes, kill or terminate malfunctioning processes, and understand Process ID details. Examples of syntax and command line options are listed, along with several methods to kill processes. The…

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

The ps command is very useful in Ubuntu Linux. It allows you to view details of the currently running processes on your system and helps you to identify any processes that might be causing issues.

You can use the ps command to kill or terminate processes that are not behaving normally or are gobbling up all your CPU time and RAM. This can help restore the system’s regular operation and prevent any damage to your system.

Additionally, the ps command provides various options that allow you to customize the output and display detailed information about the processes.

The PS command is essential for managing and troubleshooting processes on Ubuntu Linux.

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 determine 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 names 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 that are running but will be extended. 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 lists 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.


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



One response to “How to use the ps command in Ubuntu Linux with examples”

  1. Sam Christian Avatar
    Sam Christian

    awesome…you told my secretary everything about ps except where to find it. IE: Like me telling someone to ipconfig in command in windows then not telling them to click start then run. Then after spending 5 minutes on your page trying to find it, they have to go somewhere else to look that up. How can people be so smart and lack so much common sense?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading