The ps
command displays information about active processes. It offers a snapshot of the current system activity, including process IDs (PID), parent process IDs (PPID), CPU and memory usage, and the commands that initiated them. The command supports various options to tailor the output for different monitoring and troubleshooting needs.
Display Processes for the Current User
ps
Shows processes tied to the current terminal session.
List All Running Processes
ps -e
Displays all processes on the system.
Show Full Format Listing
ps -ef
-e
: All processes.-f
: Full-format output (UID, PID, PPID, CMD, etc.).
Display Processes in a Tree Format
ps -e --forest
Shows parent-child relationships between processes.
List Processes by a Specific User
ps -u username
Displays processes owned by username
.
Show Threads for a Process
ps -T -p PID
-T
: Lists threads for the process with the specifiedPID
.
Display Processes Using the Most CPU
ps -eo pid,ppid,cmd,%cpu --sort=-%cpu | head
-eo
: Custom output format (PID, PPID, CMD, CPU%).--sort=-%cpu
: Sorts by CPU usage (descending).head
: Shows the top 10 processes.
Display Processes Using the Most Memory
ps -eo pid,ppid,cmd,%mem --sort=-%mem | head
%mem
: Memory usage percentage.
Show Processes by Command Name
ps -C firefox
Lists all processes running the firefox
command.
Display Processes by Group ID
ps -g GID
Shows processes belonging to the specified group ID.
Show Processes by Terminal
ps -t tty1
Lists processes running on the tty1
terminal.
Custom Output Format
ps -eo pid,comm,pcpu,pmem,stat
pid
: Process ID.comm
: Command name.pcpu
: CPU usage.pmem
: Memory usage.stat
: Process state.
Show Processes with Parent-Child Relationships
ps -ejH
-j
: Jobs format (includes PGID, SID).-H
: Displays hierarchy.
Monitor Real-Time Processes
watch -n 1 'ps -eo pid,ppid,cmd,%cpu,%mem --sort=-%cpu'
watch
: Refreshes the output every second.
Kill a Process by PID
ps -ef | grep process_name
kill PID
- Find the PID of
process_name
, then terminate it withkill
.
Key Notes:
- Output Formats: Use
-e
,-f
, or-o
to customize output. - Sorting: Use
--sort
to order processes by CPU, memory, etc. - Real-Time Monitoring: Combine with
watch
for live updates.