Mastering Linux ‘ps’: Essential Commands to Inspect and Filter Processes
This guide explains how the Linux ps command works, details its most useful options for listing, filtering, sorting, and formatting process information, and shows how to combine it with tools like watch, less, and pstree for real‑time and hierarchical views.
What is ps?
The ps command displays a snapshot of the current processes on a Linux system; it does not update continuously, so for real‑time monitoring you would use top instead.
Basic parameters
-A(or -e): show all processes. -a: show processes attached to any terminal, including those of other users. -u: display processes grouped by user. x: often used with -a to list processes without a controlling terminal.
Output format options
l: long, detailed listing for each PID. j: jobs format. -f: full‑format listing with additional columns.
Running ps without parameters
Executing ps alone prints four default columns: PID, TTY, TIME, and CMD, which are not sorted.
Show all processes
Use -a (all) together with x to include processes lacking a terminal: ps -ax Pipe to less for easier browsing:
ps -ax | lessFilter by user
To list processes owned by a specific user, use -u followed by the username, e.g.:
ps -u pungkiFilter by CPU and memory usage
The aux option shows a comprehensive view. You can sort the output by CPU or memory usage with --sort:
ps -aux --sort -pcpu | less ps -aux --sort -pmem | lessCombine both sorts and show only the top 10 results:
ps -aux --sort -pcpu,+pmem | head -n 10Filter by process name or PID
Use -C followed by the command name (e.g., getty) to select processes: ps -C getty For a formatted view add -f:
ps -f -C gettyShow threads of a process
Display threads for a given PID with -L:
ps -L 1213Tree view of processes
Show a hierarchical tree using: ps -axjf Or use the dedicated pstree command:
pstreeDisplay security‑related information
List PID, user, and command arguments for all processes:
ps -eo pid,user,argsShow processes owned by root
Combine -U (real UID) and -u (effective UID) with a user‑format flag:
ps -U root -u root uReal‑time monitoring with watch
Pair ps with watch to refresh every second: watch -n 1 'ps -aux --sort -pmem,-pcpu' Limit the output to the first 20 lines:
watch -n 1 'ps -aux --sort -pmem,-pcpu | head -n 20'You can also filter by a specific user while watching:
watch -n 1 'ps -aux -U pungki u --sort -pmem,-pcpu | head -n 20'Conclusion
The ps command is installed on virtually every Linux distribution, making it a reliable tool for generating custom process reports; consult man ps for a complete list of options.
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.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
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.
