Master Linux Process Management with the ps Command: Tips & Examples
This guide explains the Linux ps command’s syntax, common options, and advanced usage—showing how to list processes, filter by state, view resource usage, display process trees, sort by CPU or memory, monitor in real time, and combine with kill or pkill to manage processes effectively.
Introduction
The ps command is a fundamental Linux utility for inspecting running processes, their states, and resource consumption. It is essential for system administrators and developers who need to understand and manage the processes on a host.
Basic Usage
The basic syntax is: ps [options] Running ps without options lists the processes owned by the current user.
Process States
pscan display the state of each process. Common state codes are: R: Running S: Sleeping Z: Zombie D: Uninterruptible sleep T: Stopped
Example – show only running processes:
ps aux | grep 'R'Viewing a Specific User’s Processes
Use the -u option followed by a username:
ps -u usernameDisplaying the Full Process Tree
The ps auxf command prints a hierarchical view of parent and child processes.
ps auxfResource Usage
To list processes sorted by CPU usage, showing the top ten: ps aux | sort -nrk 3,3 | head -n 10 Similarly, sorting by memory:
ps aux --sort=-%memDetailed Information for a Specific Process
The -p option selects a PID and the -o format specifier chooses which fields to display:
ps -p PID -o pid,ppid,cmd,%cpu,%memReal‑Time Monitoring
Combine ps with watch to refresh the view every second:
watch -n 1 "ps aux | grep 'process_name'"Terminating Processes
Find a process and kill it with kill -9 PID:
ps aux | grep 'process_name'
kill -9 PIDSorting by CPU or Memory
Use --sort with a minus sign to order descending:
ps aux --sort=-%cpu ps aux --sort=-%memThread Information
Show threads of a process using the -eLf options:
ps -eLf | grep 'process_name'User‑Specific Statistics
The -U option displays detailed statistics for a given user:
ps -U username uParent‑Child Relationships
List all processes with their parent IDs using the -f (full‑format) flag:
ps -efProcess Tree for a Specific User
The pstree command can be limited to a user:
pstree -u usernameWorking Directory of a Process
Use pwdx PID to reveal the current working directory of a process:
pwdx PIDKilling All Processes of a User
The pkill -u username command terminates every process owned by the specified user.
pkill -u usernameConclusion
The ps utility provides a comprehensive view of process information, from basic listings to advanced filtering, sorting, and integration with other commands for real‑time monitoring and termination. Mastering its options enables effective system performance analysis and troubleshooting.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
