Mastering the Linux ps Command: Essential Options for Process Monitoring
This guide explains how to use the Linux ps command to inspect and control processes, covering basic usage, common options, output formatting, filtering by user, CPU or memory usage, displaying process trees, security information, and real‑time monitoring with watch.
The ps command is the fundamental tool for viewing the current state of processes on a Linux system. It provides a snapshot of running processes, their IDs, owners, resource usage, and more, enabling administrators to diagnose issues, detect zombies, and monitor resource consumption.
Basic Usage and Core Options
Running ps without arguments shows a minimal set of columns (PID, TTY, TIME, CMD). The output is unsorted and reflects the state at the moment of execution. -A or -e: display all processes. -a: show processes associated with a terminal, including those of other users. -u: display processes with user‑oriented columns. x: include processes without a controlling terminal (often used with -a).
Output Formatting
-l: long format with detailed information. -j: jobs format. -f: full format, showing parent‑child relationships.
Practical Examples
1. Default output (no parameters)
$ psThe default view shows four columns: PID, TTY, TIME, and CMD.
2. Show all processes
$ ps -ax
$ ps -ax | less3. Filter by user
$ ps -u pungki4. Sort by CPU or memory usage
$ ps -aux | lessTo sort ascending by CPU:
$ ps -aux --sort -pcpu | lessTo sort ascending by memory:
$ ps -aux --sort -pmem | lessCombine both and show the top 10 results:
$ ps -aux --sort -pcpu,+pmem | head -n 105. Filter by process name or PID
$ ps -C gettyFor more detail, add -f:
$ ps -f -C getty6. Show threads of a specific PID
$ ps -L 12137. Display processes as a tree
$ ps -axjfAlternatively, use the dedicated pstree command:
$ pstree8. Show security‑related information
$ ps -eo pid,user,argsThis lists each process’s PID, the user that started it, and the command line arguments.
9. Show processes created by the root user
$ ps -U root -u root uThe -U flag filters by real UID, -u by effective UID, and the final u selects a user‑oriented output format.
10. Real‑time monitoring with watch
Combine ps with watch to refresh every second:
$ watch -n 1 'ps -aux --sort -pmem,-pcpu'Limit the view to the top 20 entries:
$ watch -n 1 'ps -aux --sort -pmem,-pcpu | head -n 20'For user‑specific real‑time monitoring:
$ watch -n 1 'ps -aux -U pungki u --sort -pmem,-pcpu | head -n 20'Conclusion
The ps utility is available on virtually every Linux distribution, making it a reliable choice for generating custom process reports. By mastering its myriad options, administrators can tailor output to their exact needs, and further explore additional flags via man ps.
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.
