Linux ps command options
The ps
(process status) command in Linux provides detailed information about running processes on the system. Below, I'll explain several common ps
command options and provide examples of their usage and the resulting output.
1. ps
(Default Usage)
By default, ps
shows processes running in the current terminal session.
Sample Output:
- PID: Process ID.
- TTY: Terminal associated with the process.
- TIME: Cumulative CPU time the process has used.
- CMD: The command or program that started the process.
2. ps -e
or ps -A
(Show All Processes)
This option lists all processes running on the system, not just those associated with the current terminal.
Sample Output:
- This displays all system processes, including system daemons.
3. ps -f
(Full Format)
This option shows a more detailed listing of the processes, including the parent process ID (PPID), user ID (UID), and command with its arguments.
Sample Output:
- UID: User ID of the process owner.
- PID: Process ID.
- PPID: Parent Process ID.
- C: CPU utilization.
- STIME: Start time of the process.
- CMD: Command and its arguments.
4. ps -u <username>
(Show Processes for Specific User)
This option filters processes by a specific user, showing only those owned by that user.
Sample Output:
- This will show only the processes run by the
root
user.
5. ps -a
(Show Processes for All Users)
Displays all processes associated with terminals, including those of other users (excluding session leaders).
Sample Output:
- This shows processes in the terminal, including those from other users, excluding daemon processes.
6. ps -x
(Show Processes Without a Terminal)
This option shows processes that are not associated with a terminal (i.e., background processes, daemons).
Sample Output:
- This will display processes that are not attached to a terminal (such as daemons).
7. ps aux
(Show All Processes with Detailed Info)
The aux
option combination provides a detailed view of all running processes on the system, including processes from all users, with information such as CPU and memory usage.
Sample Output:
- USER: The user who owns the process.
- PID: Process ID.
- %CPU: Percentage of CPU usage by the process.
- %MEM: Percentage of memory usage by the process.
- VSZ: Virtual memory size of the process.
- RSS: Resident Set Size (physical memory the process is using).
- STAT: Process status (e.g.,
S
for sleeping,R
for running). - START: Process start time.
- TIME: Cumulative CPU time used by the process.
- COMMAND: Command that started the process.
8. ps -l
(Long Format)
This option provides a longer, more detailed format with additional columns, including flags, priority, and memory information.
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: Process priority.
- NI: Nice value.
- ADDR: Memory address where the process is loaded.
- SZ: Size of the process in memory.
- WCHAN: If sleeping, shows the event the process is waiting for.
- TTY: Terminal associated with the process.
- TIME: CPU time used.
- CMD: Command and its arguments.
9. ps -o <format>
(Custom Output Format)
You can specify a custom output format to display only selected information, such as process ID, memory usage, or CPU usage.
Sample Output:
- This command shows the process ID, user ID, elapsed time, and command.
10. ps -p <pid>
(Show Specific Process)
Use the -p
option followed by a process ID (PID) to display information about a specific process.
Sample Output:
- This shows the process details for the process with PID 101.
Conclusion:
The ps
command in Linux offers various options to monitor and display detailed information about processes. By using options such as -e
, -f
, -u
, aux
, and -o
, you can tailor the output to meet your needs, making it a powerful tool for process management and troubleshooting.