Operations 9 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering the Linux ps Command: Essential Options for Process Monitoring

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)

$ ps
ps default output
ps default output

The default view shows four columns: PID, TTY, TIME, and CMD.

2. Show all processes

$ ps -ax
$ ps -ax | less
ps -ax output
ps -ax output

3. Filter by user

$ ps -u pungki
ps -u user output
ps -u user output

4. Sort by CPU or memory usage

$ ps -aux | less

To sort ascending by CPU:

$ ps -aux --sort -pcpu | less
ps sorted by CPU
ps sorted by CPU

To sort ascending by memory:

$ ps -aux --sort -pmem | less
ps sorted by memory
ps sorted by memory

Combine both and show the top 10 results:

$ ps -aux --sort -pcpu,+pmem | head -n 10

5. Filter by process name or PID

$ ps -C getty
ps -C getty
ps -C getty

For more detail, add -f:

$ ps -f -C getty
ps -f -C getty
ps -f -C getty

6. Show threads of a specific PID

$ ps -L 1213
ps -L threads
ps -L threads

7. Display processes as a tree

$ ps -axjf
ps tree view
ps tree view

Alternatively, use the dedicated pstree command:

$ pstree
pstree output
pstree output

8. Show security‑related information

$ ps -eo pid,user,args

This lists each process’s PID, the user that started it, and the command line arguments.

ps -eo output
ps -eo output

9. Show processes created by the root user

$ ps -U root -u root u

The -U flag filters by real UID, -u by effective UID, and the final u selects a user‑oriented output format.

ps root processes
ps root processes

10. Real‑time monitoring with watch

Combine ps with watch to refresh every second:

$ watch -n 1 'ps -aux --sort -pmem,-pcpu'
watch ps output
watch ps output

Limit the view to the top 20 entries:

$ watch -n 1 'ps -aux --sort -pmem,-pcpu | head -n 20'
watch top processes
watch top processes

For user‑specific real‑time monitoring:

$ watch -n 1 'ps -aux -U pungki u --sort -pmem,-pcpu | head -n 20'
watch user processes
watch user processes

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellUnixSystem Administrationprocess monitoringps command
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.