The ps
command is used to display information about currently running processes on a Linux system. It provides details such as process ID (PID), terminal associated with the process, CPU time, and the command that started the process.
-
Syntax:
ps [options]
-
Examples:
ps
- Displays a snapshot of the current user's processes in the current shell.
ps aux
- Displays detailed information about all running processes on the system.
ps -ef
- Displays a full-format listing of all processes.
-
a
:- Shows processes for all users, not just the current user.
ps a
- Lists all processes associated with terminals.
-
u
:- Displays processes in a user-oriented format, showing the user who owns each process.
ps u
- Provides a user-friendly output of processes.
-
x
:- Includes processes that do not have a controlling terminal.
ps x
- Lists processes, including those started by
init
orcron
.
-
-e
or--everyone
:- Shows information about all processes.
ps -e
- Lists all processes running on the system.
-
-f
or--full
:- Displays a full-format listing of processes, showing more detailed information.
ps -f
- Provides a more comprehensive view of processes.
-
aux
:- Commonly used to show all processes (
a
), user-oriented format (u
), and include processes without a terminal (x
).
ps aux
- Displays detailed information about all processes, including memory and CPU usage.
- Commonly used to show all processes (
-
-p [PID]
or--pid [PID]
:- Shows information for a specific process by its process ID.
ps -p 1234
- Displays details about the process with PID 1234.
-
-T
:- Displays threads of a process along with the processes themselves.
ps -T
- Shows the threads associated with the current shell.
-
-C [command]
:- Selects processes by command name.
ps -C bash
- Lists all
bash
processes.
-
--sort [KEY]
:- Sorts the output by the specified key (e.g.,
pid
,uid
,cpu
,mem
).
ps aux --sort=-%mem
- Sorts processes by memory usage in descending order.
- Sorts the output by the specified key (e.g.,
-
--help
:- Displays help information about the
ps
command.
ps --help
- Shows usage information and available options.
- Displays help information about the
-
Viewing All Processes:
- Use
ps aux
to get a comprehensive list of all processes.
ps aux
- Provides detailed process information, including the user and memory usage.
- Use
-
Filtering by User:
- Use the
-u
option with a username to filter processes by a specific user.
ps -u username
- Lists all processes owned by
username
.
- Use the
-
Filtering by Command:
- Use the
-C
option to filter by the command name.
ps -C nginx
- Displays all processes related to the
nginx
command.
- Use the
-
Sorting by Resource Usage:
- Use
--sort
to sort processes by CPU or memory usage.
ps aux --sort=-%cpu
- Lists processes sorted by CPU usage in descending order.
- Use
The ps
command is a powerful tool for monitoring and managing processes on a Linux system. It allows users and administrators to view real-time information about running processes, filter and sort them based on various criteria, and diagnose system performance issues. Proper use of ps
helps in understanding the system's state and managing processes effectively.