Understanding the ps Command

Basic Usage of ps

The ps command in Linux is used to display information about active processes. It stands for "process status" and gives a snapshot of the current processes running in the system at the time it is invoked.

ps [OPTIONS]

Options Available with ps

-e (All Processes)

Show all processes running on the system:

ps -e

This option displays every process running on the system, including system and user processes.

-f (Full Format Listing)

Show a full listing of processes with more detailed information:

ps -f

This option shows more detailed information, such as the parent process ID (PPID), user, and command.

-u (User Format)

Display processes for a specific user:

ps -u username

This shows processes owned by a specific user.

-aux (Detailed Information)

Displays detailed information about all processes, including user, PID, CPU usage, and memory usage:

ps aux

This is commonly used to display all running processes in a detailed manner.

-l (Long Format Listing)

Show processes in long format:

ps -l

This option provides detailed information, including flags, state, and priority of processes.

-p (Specify Process ID)

Display information about a specific process by its PID:

ps -p PID

Here, PID refers to the process ID. This option allows you to view detailed information about a particular process.

-T (Show Threads)

Display information about threads:

ps -T

This option lists all threads for a specific terminal.

--forest (Display Hierarchical View)

Display processes in a hierarchical tree format:

ps --forest

This shows the parent-child relationships between processes.

-C (By Command Name)

Select processes by command name:

ps -C commandname

This option allows you to select and display processes based on the command name.

--sort (Sort Output)

Sort processes by a specific column, such as CPU or memory usage:

ps --sort=-pcpu

This sorts the output by the percentage of CPU usage in descending order.

-o (Custom Output Format)

Customize the output format by selecting specific columns:

ps -eo pid,cmd,pcpu,pmem

This displays the PID, command, CPU usage, and memory usage of all processes.

--help

Display help information about the ps command:

ps --help

Examples of ps Command

List All Processes

ps -e

This command lists all processes currently running on the system.

View Processes for a Specific User

ps -u root

This displays processes owned by the user root.

Detailed Process Information

ps aux

This command provides detailed information about all running processes, including CPU and memory usage.

Displaying a Specific Process by PID

ps -p 1234

This shows information about the process with PID 1234.

Hierarchical Process View

ps --forest

This command shows processes in a tree structure to visualize parent-child relationships.

Summary of Options

Option Description
-e Display all processes.
-f Show full format listing.
-u Display processes for a specific user.
aux Display detailed information about all processes.
-l Show processes in long format.
-p Show information for a specific process ID.
-T Show threads for a specific terminal.
--forest Display processes in a hierarchical tree format.
-C Select processes by command name.
--sort Sort processes by a specific column.
-o Customize the output format.

Manual Pages

For more detailed information, you can refer to the manual page for the ps command:

man ps