WebMasterCampus
WEB DEVELOPER Resources

Linux ps Command

Learn Linux ps Command with examples


Linux ps Command

In Linux, we can use “ps” command stands for process status and is a powerful tool that provides information about processes on your Linux system.

The ps command allows you to list the status of processes running on your system easily.

The ps command show sprocesses, including their ID, priority, memory usage, CPU usage, and more.

ps Command Syntax

>> ps [OPTIONS]

By default, the tool will only provide simple information.

ps Command Example

>> ps

  PID TTY          TIME CMD
   10 pts/0    00:00:00 bash
  115 pts/0    00:00:00 ps

Headers from ps Command

Command Description
PID This is the process ID given to the process when it was started.
TTY This value represents the terminal used to initiate this process.
TIME Using this value; you can tell how much CPU time this process has consumed since it first started running.
CMD The final value represents the command used to start this process.

You can use this ID for various tasks, including killing the process or changing its nice value.

ps -f Command

ps -f for Displaying the Full Format Listing.

>> ps -f

Full Format Listing Headers from the ps Command

Command Description
UID The user that started this process. This value will be shown as the user’s name.
PID Value representing the unique process ID. You can use this ID to interact with the process.
PPID This is the ID belonging to the parent process. The parent process is the one that initiated this process.
C The amount of CPU that this process is currently consuming.
STIME The time the process was started on the current system.
TTY The terminal that was used when starting this process.
TIME The amount of CPU time this process has consumed since it began running.
CMD The command that was used to start this process.

If the process started in a different year to when you ran the ps command, this option would display the year using the format “YYYY”. For example, “2022”.

If the process was not started on the current day, it would be displayed in the “MmmDD” format. So, for example, the result would appear as “Feb07”.

If the process was started the same day as when you executed ps it would use the format “HH:MM”. For example, a valid output is shown as “04:39”.

Using the “extended” version of the full format option, you will get these additional columns.

ps -F Command

ps -f for Displaying the Extended Full Format Listing

>> ps -F

Additional columns with extended version of full format

Command Description
SZ The size in physical pages of the core image of the process. This includes text; data; stack space; and more.
RSS The resident set size is the total amount of non-swapped physical memory used by the process. This value is displayed in kilobytes.
PSR The processor that this process is currently assigned to.

ps -l Command

ps -l to Retrieving the Long Format from the ps Command

The long format provides a few different headers to what is provided by the “full format”.

>> ps -l

Headers from the ps -l Command Using the Long Option

F – The sum of all flags that have been set for this process.

Below are two possible flags that can be set.

  • 1 – Forked but didn’t execute
  • 4 – Used super-user privileges
  • S – The code shows the status of the process.

Below is a list of the potential status codes that can be shown for a process.

  • D – Uninterruptible sleep. This status usually means it’s waiting on IO to complete.
  • I – Idle kernel thread
  • R – Running or runnable
  • S – Interruptible sleep
  • T – Stopped by a job control signal
  • t – Stopped by debugger during the tracing
  • W – Paging (Only valid on kernels older than 2.6.xx)
  • X – Process is dead
  • Z – Zombie process, terminated but has not yet been removed by the parent process
  • UID – Unique ID of the user that started this process
  • PID – The unique ID that is used to identify this specific process on the system.
  • PPID – This value represents the parent processes unique ID. This is the process that launched the current process.
  • C – CPU Usage of the process when this command was run.
  • PRI – Priority of the process. A higher value indicates a lower priority. A lower value represents a higher priority.

Linux’s scheduler utilizes this to know how to handle this process.

  • NI – The nice value that has been set for this process. This value is used to adjust the priority
  • ADDR – The memory address of the process.
  • SZ – This value shows the amount of virtual memory this process is using.
  • WCHAN – If the process is sleeping, this will be the name of the kernel function in which it is sleep.

A hyphen ("-") will be displayed if the process is currently running.

The command will show an asterisk ("*") will be shown in the terminal if the process is multi-threaded and displaying threads is disabled.

  • TTY – The terminal that is in control of this process, or the one used to start it.
  • TIME – The amount of CPU time this process has consumed since it began running.
  • CMD – The command that was used to start up this process.

ps -A Command

ps -A Display All Processes

By default, the ps command will only print processes belonging to the calling user and that specific terminal session.

>> ps -A

This tool can also print information about all running processes using the “-A” or “-e” option.

By default, this list of processes will be ordered by their process ID.

ps -u Command

Syntax for Selecting Processes by EUID

Select processes that have your specified effective user ID (EUID) or username.

The effective user id is the user whose file access permissions are being utilized by the process.

The user value can either be their ID or their username.

>> ps -u USER

Syntax for Selecting Processes by RUID

You can also select processes by specifying their real user ID (RUID), or username.

The real user ID is the user’s ID that started the process. To search using the real user ID, you need to use the option “-u USER”. You can either use the user’s ID or their username.

>> ps -u USER

ps command to find processes with the effective user id set to “1000”

ps -u while referencing the user id of “1000” after it.

>> ps -u 1000

Alternatively, we can also use the user’s name to achieve the same thing without utilizing its ID.

>> ps -u pi

ps -g Command

The ps command allows you to select processes by an associated group ID or name.

The utility separates this into two categories

  • the effective group id
  • the real group id

ps Command Selecting Processes Based on Their Effective Group ID

The effective group id (EGID) reflects the group that the process uses for its file access permissions.

>> ps -g GROUP
>> ps -g 1000

Additionally, we can reference this same group by using its name, which is “pi”.

>> pg -g pi

ps -G Command Select Processes by their Real Group ID

The real group id (RGID) represents the group of the user that started the process.

>> pg -G Syntax
>> pg -G 1000

Additionally, we can reference this same group by using its name, which is “pi”.

>> pg -G pi

ps -C Command

ps -C Selecting Processes Based on Their Command Name. The command name isn’t the full command, but the portion used to start the program itself.

For example, if you run the command “vim example.txt”, the command name would be “vim”.

To list processes based on the command name, you will need to use the “-C CMDNAME” option.

This option supports multiple command names. Each one needs to be separated by a comma (",")

>> ps -C CMDNAME
>> ps -C vim

ps -p Command

The ps command allows you to fine-tune its selection by specifying either the process ID or the parent process ID.

To narrow the ps command down to a specific process ID (PID), you need to use the “-p PID” option.

ps -p PID Command

>> ps -p PID
>> ps -p 11211

You can also select processes by their parent process id (PPID). This option is slightly different and requires you to use “–ppid PID”.

ps -ppid PID Command

Selecting using the parent process ID allows you to list all processes that a single process has started.

>> ps --ppid PID
>> ps --ppid 4730

You can reference multiple process IDs by separating each value by a comma “,”.

ps -p Multiple Process IDs

We can also reference multiple process IDs by separating each value by a comma.

>> ps -p 11211,4730

ps -t TTY Command

The ps command features an option that allows you to select all processes started by a specific terminal.

To list processes based on the tty that started them, you need to use the “-t TTY” option. With this option, you need to specify the terminal ID you want to get the processes from.

>> ps -t TTY

We will list all processes started under the “pts/0” terminal. All we need to do is use the “-t” option, followed by the terminal we want to look for, which in our case is “pts/0”.

>> ps -t pts/0
Created with love and passion.