Linux ps command
The ps
(process status) command in Linux is used to display information about active processes running on the system. It provides details such as process IDs (PID), user, CPU usage, memory usage, and more. It is commonly used for monitoring and managing processes.
Basic Syntax:
By default, ps
will show the processes running in the current terminal session.
Commonly Used Options:
a
: Show processes for all users.u
: Display processes in a user-oriented format (with user info).x
: Show processes that are not attached to a terminal.-e
or-A
: Show all processes running on the system.-f
: Show a full-format listing with additional details such as parent PID and the command with its arguments.-l
: Display a long-format listing with additional columns.-o
: Specify custom output format (you can choose specific columns to display).-p
<pid>: Show processes with a specific process ID.-h
: Display help message.
Basic Usage:
Example Output:
- PID: Process ID, the unique identifier for each running process.
- TTY: The terminal from which the process is running (e.g.,
pts/0
). - TIME: The cumulative CPU time the process has used.
- CMD: The command or program name that started the process.
Example with ps -e
or ps -A
(Show all processes):
Sample Output:
- This shows all processes running on the system, not just those related to the current terminal session.
Example with ps -f
(Full-format listing):
Sample Output:
- UID: User ID (owner of the process).
- PID: Process ID.
- PPID: Parent Process ID (the ID of the process that started this process).
- C: CPU utilization of the process.
- STIME: Start time of the process.
- TTY: Terminal associated with the process.
- TIME: Cumulative CPU time.
- CMD: The command that started the process.
Example with ps -u <username>
(Show processes for a specific user):
Sample Output:
- This shows all processes running under the specified user (e.g.,
root
).
Example with ps aux
(Show all processes with detailed info):
Sample Output:
- USER: The user who owns the process.
- PID: Process ID.
- %CPU: CPU usage percentage.
- %MEM: Memory usage percentage.
- VSZ: Virtual memory size of the process (in KB).
- RSS: Resident Set Size (physical memory the process is using).
- TTY: Terminal associated with the process.
- STAT: Process status (e.g.,
S
for sleeping,R
for running). - START: The time the process started.
- TIME: Cumulative CPU time.
- COMMAND: The command that started the process.
Example with ps -l
(Long format):
Sample Output:
- F: Flags associated with the process.
- S: Process state (e.g.,
S
for sleeping). - UID: User ID of the process owner.
- PID: Process ID.
- PPID: Parent Process ID.
- C: CPU usage.
- PRI: Priority.
- NI: Nice value (priority adjustment).
- ADDR: Address in memory where the process is loaded.
- SZ: Size in memory (in KB).
- WCHAN: If the process is sleeping, shows the event it's waiting for.
- TTY: Terminal associated with the process.
- TIME: Cumulative CPU time used by the process.
- CMD: Command used to start the process.
Example with ps -p <pid>
(Show specific process):
Sample Output:
- This shows information about a specific process (with PID
101
).
Example with ps -o <format>
(Custom output format):
Sample Output:
- The
-o
option allows you to customize the output format, specifying only the columns you want to see (e.g.,pid
,uid
,etime
,comm
).
Conclusion:
The ps
command is a versatile and widely used tool to view and manage processes on a Linux system. It provides essential information about the processes running on your machine, such as process IDs, CPU and memory usage, command names, and more. By using the various options and flags, you can tailor the output to display the specific information you need, which is invaluable for monitoring and troubleshooting system performance.