Skip to main content
SysAdmin Shell Scripting Essentials

linux show processes: ps command reference with examples

linux show processes is the operation of inspecting running process snapshots using commands like ps, top, htop, and pstree.

ps -ef      # Full-format listing with PPID
ps aux      # BSD-style verbose listing
ps -u [user] # Processes by effective user ID

Tested on Ubuntu 22.04 with Linux 5.15.x; verify against vendor docs for non-Debian distributions or older kernels.

Syntax

ps [options]

# Common patterns:
ps -ef                              # Full-format listing with PPID
ps aux                              # BSD-style verbose listing
ps -u [user]                        # Processes by effective user ID
ps -U [user]                        # Processes by real user ID
ps -C [command]                     # Filter by command name
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head   # Sort by memory

Options and Flags

Flag Type Default Description
-ef POSIX N/A Shows full-format list with PPID, all processes
-aux BSD N/A Shows all processes user-oriented (includes TTY, %CPU, %MEM)
-u [user] POSIX None Select processes by effective user ID (EUID)
-U [user] POSIX None Select processes by real user ID (RUID)
-C [cmd] POSIX None Select processes by exact command name
-l Both N/A Long format (adds UID, PID, PPID, PRI, NI, etc.)
-eo POSIX N/A User-defined output format (pid,ppid,cmd,...)
--color GNU auto Colorize output (auto, always, never)

Usage Examples

1. Display all processes with PPID

ps -ef

Prints every process in full-format including parent process ID (PPID). This POSIX-compliant command is the standard way to view the complete process snapshot. Use for debugging orphaned or zombie processes.

See also  cmd /c /k Run Bat File: Syntax, Exit Codes, Troubleshooting

2. Filter processes by effective user (EUID)

ps -u vivek u

Lists all processes owned by user vivek in user-oriented format (u). The -u flag selects by EUID; includes processes even if SUID is set. Typical for diagnosing per-user resource usage.

3. Show process tree with pstree

pstree -l -a -p -s vivek

Displays hierarchical tree for user vivek with command-line arguments (-a), PIDs (-p), and parent chain (-s). -l prevents line truncation. Faster than ps --forest for deep trees.

Troubleshooting & Common Errors

Error Message/Code Root Cause Resolution Command
ps: command not found Minimal container (Alpine) missing procps apk add procps or apt install procps
ps: invalid option -- 'z' Non-existent flag used Check man ps for valid flags; use ps -ef
No output for -u username User typed incorrectly or has no running processes id -u username to verify UID; ps -e | grep username
ps: Unsupported option (BSD) – > Mixing POSIX and BSD options on different systems Choose one style: ps aux (BSD) or ps -ef (POSIX)

Performance Considerations and Tuning

Listing processes with ps reads every entry in /proc. On systems with thousands of processes or containers, this scan can be slow. Filter early, use lightweight tools, and adjust kernel limits.

  • Filter by user or command name: ps -U vivek u reduces scan to only that user’s processes. ps -C nginx restricts to a specific command, skipping unrelated entries.
  • Use pgrep for fast PID lookups: pgrep -u www-data queries kernel process table directly, avoiding /proc traversal.
  • Tune the PID namespace: kernel parameter kernel.pid_max (in /proc/sys/kernel/pid_max) sets maximum PID number; larger values increase scan directories. Set to match workload.
  • Limit output fields: ps -ef is lighter than ps auxf. Fewer columns reduce processing as noted in the ps man page.
# Measure time for full vs. filtered process list
time ps -ef > /dev/null          # scans all /proc
time ps -U postfix u > /dev/null # filtered, faster

For continuous monitoring, top and htop use incremental reads and are more efficient than repeated ps calls.

See also  Find IP Address in Linux – CLI Commands Reference

Multi-Cloud Context

Process inspection remains OS-level; no cloud CLI subcommand directly lists guest processes. The table below shows how to invoke process listing inside cloud VMs.

Feature Linux (ps) AWS (EC2) Azure (VM) GCP (Compute)
Show all processes ps -ef via SSH or Systems Manager Run Command via SSH or Run Command (Azure CLI) via SSH or OS Login / gcloud compute ssh
Filter by user ps -u vivek aws ssm send-command with script az vm run-command invoke with inline ps gcloud compute ssh --command "ps -u vivek"

Verified References

Every command was cross-checked against official manual pages, kernel.org, and vendor documentation. Commands confirmed in those sources are listed below; any without an authoritative match are flagged for verification before production use.

Command Source Notes
ps manpages.ubuntu.com This version follows Linux usage of not printing header unless BSD personality selected
head man7.org Part of coreutils; available via info '(coreutils) head invocation'
time ps manpages.ubuntu.com Ubuntu Manpage Repository
grep nginx manpages.ubuntu.com Ubuntu Manpage Repository
ps aux Not found in authoritative documentation — verify before production use.
ps vivek Not found in authoritative documentation — verify before production use.

Frequently Asked Questions

What is the difference between ps aux and ps -ef?

Answer: ps aux uses BSD syntax showing USER, PID, %CPU, %MEM, VSZ, RSS, STAT, START, TIME, COMMAND. ps -ef uses POSIX syntax showing UID, PID, PPID, C, STIME, TTY, TIME, CMD. Both list all processes; BSD includes memory/CPU percentages and is preferred for resource inspection. POSIX includes parent PID for tree debugging. For parsing, ps aux is common in Linux scripts but note that on BSD/macOS the columns differ.

# BSD style
ps aux | grep nginx
# POSIX style
ps -ef | grep nginx

How do I fix “ps: invalid option — ‘a'” error?

Answer: This error occurs when using BSD-style ps aux on a POSIX-only ps implementation (e.g., BusyBox). Workarounds:

# POSIX style
ps -ef
# On macOS with procps installed via Homebrew
/usr/local/bin/ps aux

To detect compatibility, run ps --version 2>/dev/null; procps-ng prints version, BusyBox shows “ps: invalid option”.

Does --sort work on all Linux distributions?

Answer: Yes, ps --sort is part of procps-ng and works on all major Linux distros (Ubuntu, RHEL, Debian, Arch). Sort by memory:

ps aux --sort=-%mem
# POSIX portable (also works on BSD)
ps -eo pid,comm,rss --sort=-rss | head

On non-Linux systems, use awk or sort piped: ps aux | sort -k4 -rn.

What is the fastest way to show processes with high memory usage on Linux?

Answer: Fastest one-off query: ps aux --sort=-%mem | head -n 20. For automation without headers:

ps aux --sort=-%mem --no-headers | head -n 10
# Continuous monitoring (lower overhead)
top -b -n 1 -o %MEM | head -n 20

For real-time streaming, htop with --sort-key=MEM is interactive but heavier.