ps
List running processes
TLDR
List all running processes
List all running processes including the full command string
Search for a process that matches a string (the brackets will prevent grep from matching itself)
List all processes of the current user in extra full format
List all processes of the current user as a tree
Get the parent PID of a process
Sort processes by memory consumption
SYNOPSIS
ps [options]
PARAMETERS
-A
Select all processes.
-e
Select all processes.
a
Select all processes on a terminal, including those of other users.
u
Display the user-oriented format output.
x
Include processes without controlling terminals (daemons).
-f
Display a full listing format.
-o
Define the output format (e.g., pid, uid, comm, pcpu, pmem).
-p
Select processes by process ID.
-u
Select processes by user ID or name.
-C
Select processes by command name.
--forest
Display process relationships as a tree.
DESCRIPTION
The `ps` command in Linux provides a snapshot of the current processes running on the system. It displays information about each process, such as its process ID (PID), user ID (UID), CPU usage, memory usage, command name, and execution state. `ps` is a fundamental tool for system administrators and developers to monitor system activity, diagnose performance issues, and identify resource-intensive processes. Various options are available to customize the output, including selecting specific users or groups, displaying different information fields, and formatting the output for easy parsing. By default, `ps` shows processes associated with the current user in the current terminal. Understanding `ps` and its options is crucial for effectively managing and troubleshooting Linux systems.
It helps to understand what is happening on the system and quickly pinpoint resource usage.
CAVEATS
The specific information displayed by `ps` and the available options can vary slightly between different Linux distributions and versions of the `procps` package.
UNDERSTANDING OUTPUT COLUMNS
The `ps` output typically includes columns like PID (Process ID), TTY (Controlling Terminal), STAT (Process Status), TIME (CPU Time), and COMMAND (Command Name).
STAT codes can indicate various states like 'R' (running), 'S' (sleeping), 'Z' (zombie), and 'T' (stopped).
Use `man ps` or `ps --help` for a complete list of output format options, and corresponding meaning.
PROCESS STATES
Different states can be represented by the process flags. A process can be running (R), sleeping (S), stopped (T), or a zombie (Z). Understanding these states helps in diagnosing process-related issues.
HISTORY
The `ps` command has its roots in early Unix systems. Over time, it has evolved to include more features and options for process monitoring. The basic functionality has remained consistent: to provide a snapshot of running processes. The `procps` package on Linux is the main implementation.