The ps
Command: Process Status
Summary
The ps
command is a powerful tool for displaying information about active processes on a Linux system. It allows you to monitor running applications, identify resource usage, and troubleshoot system issues.
Introduction
The ps
command, short for "process status," provides a snapshot of the current processes running on your system. It displays information such as the process ID (PID), CPU usage, memory usage, and the command being executed. Unlike tools like top
which provide a dynamic, real-time view, ps
captures a single moment in time. It's invaluable for scripting and automation tasks where you need to retrieve specific process information programmatically.
Use case and Examples
Listing All Processes Associated with the Current User
This command shows processes associated with the current user in the current terminal. It will display PID, TTY, TIME, and CMD.Listing All Processes Running on the System
This command displays a comprehensive list of all processes running on the system, regardless of the user.a
shows processes of other users, u
displays user-oriented format, and x
shows processes without controlling tty. This output includes a lot more information like user, CPU usage, memory usage, start time and the full command used to execute the process. Listing Processes by User
Replaceusername
with the actual username. This displays processes owned by the specified user. Listing Processes by PID
ReplacePID
with the actual process ID. This will only show the process with the specific PID. Combining ps
with grep
to find a specific process
process_name
with the name of the process you're looking for. This command pipes the output of ps aux
to grep
, which filters the results to show only lines containing the specified process name. This is a very common and useful technique. Commonly used flags
Flag | Description | Example |
---|---|---|
a | Display processes for all users. | ps a |
u | Display user-oriented format. | ps u |
x | Include processes without controlling terminals. | ps x |
e | Display every process on the system. | ps e |
f | Display a full listing. | ps f |
-p <PID> | Specify a list of process IDs. | ps -p 1234,5678 |
-u <username> | Specify the username to filter processes. | ps -u john |
-C <command> | Select by command name. | ps -C firefox |