Master Linux ps Command: Powerful Tips for Process Monitoring & Reporting
Learn how to master the Linux ps command—from basic options and output formats to advanced filtering by user, CPU, memory, threads, and tree view, plus real-time monitoring with watch—so you can generate custom process reports for effective system administration.
1. What is ps?
To monitor and control processes you first need to know their current state; the ps command displays a snapshot of running processes, showing which are active, terminated, zombie, or consuming excessive resources.
ps shows a snapshot of process status, not a continuous stream. For real‑time monitoring use top.
Basic options:
-A: show all processes (same as -e)
-a: show processes attached to terminals, including those of other users
-u: display information in a user‑oriented format
x: usually combined with -a to list processes without a controlling terminal
Output format options:
l: long, detailed listing of each PID
j: jobs format
-f: full‑format listing
2. What does ps output without parameters?
Running ps with no arguments displays four columns: PID, TTY, TIME, and CMD. The rows are not sorted.
3. How to display all current processes?
Use the -a option (all) and optionally x to include processes without a controlling terminal. $ ps -ax You can pipe the output to less for easier navigation.
4. How to filter by user?
Use -u followed by the username. Example for user pungki:
$ ps -u pungki5. How to filter by CPU and memory usage?
Use the aux options to display comprehensive information: $ ps -aux | less Sort by CPU usage (descending):
$ ps -aux --sort -pcpu | lessSort by memory usage (descending):
$ ps -aux --sort -pmem | lessCombine both sorts and show the top 10 results:
$ ps -aux --sort -pcpu,+pmem | head -n 106. How to filter by process name or PID?
Use -C followed by the command name. Example for the getty process: $ ps -C getty For more detail add -f:
$ ps -f -C getty7. How to filter by thread?
Use -L with the PID of the process whose threads you want to list:
$ ps -L 12138. How to display processes as a tree?
Use the -axjf options for a tree‑like view, or the dedicated pstree command:
$ ps -axjf$ pstree9. How to show security information?
Display who is logged in and what they are running:
$ ps -eo pid,user,args -eshows all processes; -o controls the output columns (PID, User, Args).
10. How to format output for processes created by root?
Filter by real and effective UID of root and use the user‑oriented format:
$ ps -U root -u root u11. How to monitor processes in real time with ps?
Combine ps with watch to refresh every second:
$ watch -n 1 'ps -aux --sort -pmem, -pcpu'Limit to the top 20 lines:
$ watch -n 1 'ps -aux --sort -pmem, -pcpu | head 20'Filter for a specific user (e.g., pungki) while watching:
$ watch -n 1 'ps -aux -U pungki u --sort -pmem, -pcpu | head 20'12. Conclusion
The ps command is versatile for generating custom reports; it is installed by default on all Linux distributions. Remember to consult man ps for a complete list of options.
Source: https://juejin.im/post/5bf9213ce51d452237153c5c
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
