Linux ps Command Examples

ps (process status) displays a snapshot of currently running processes. It is the primary tool for inspecting what is running on a Linux system, finding PIDs, checking CPU and memory usage, and understanding process relationships. Master ps to diagnose and manage your system effectively.

LinuxpsProcessesCLI
Basic Listing
List all running processes
ps aux
a shows processes for all users, u displays user-oriented format (shows %CPU, %MEM, command), and x includes processes without a controlling terminal (daemons). This is the standard starting point for process inspection.
Show process tree
ps axjf
The f flag renders a visual ASCII tree showing parent-child process relationships. This makes it easy to see which processes spawned which others — useful for understanding how a web server or app server is organized.
Show processes for current user
ps -u $USER
The -u username flag filters processes owned by a specific user. Using $USER automatically expands to your current username. Useful for seeing only your own processes on a shared system.
Show custom columns
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu
The -e selects all processes and -o specifies custom output columns. This shows PID, parent PID, command, memory %, and CPU % sorted by CPU descending. A powerful pattern for tailored process monitoring.
Filtering
Find a process by name
ps aux | grep nginx
Pipe ps output to grep to filter for a specific process name. The grep process itself will appear in results — filter it out with grep -v grep or use pgrep nginx instead for cleaner output.
Show process by PID
ps -p 1234
The -p flag shows information for a specific PID. You can specify multiple PIDs separated by commas: ps -p 1234,5678. Useful when you already know the PID from a log file or another tool.
Show all threads
ps -eLf
The -L flag shows individual threads alongside processes. The LWP column shows the thread ID. Use this when diagnosing multi-threaded applications like Java services or Node.js clusters.
Sorting & Monitoring
Top 10 processes by CPU usage
ps aux --sort=-%cpu | head -11
Sort ps output by CPU descending with --sort=-%cpu and pipe to head to show only the top consumers. The header line is included so use head -11 to see 10 processes. Useful for quickly identifying CPU hogs.
Top 10 processes by memory usage
ps aux --sort=-%mem | head -11
Sort by memory percentage descending to find processes consuming the most RAM. Combine with watch to auto-refresh: watch -n 2 'ps aux --sort=-%mem | head -11' for a live updating view.
Watch a specific process
watch -n 1 'ps aux | grep myapp | grep -v grep'
The watch command re-runs a command at regular intervals. This refreshes the process list every second, filtered for your app. Useful for monitoring restart behavior, resource trends, or verifying a deployment went live.

How to Use

  1. Run ps aux to see all running processes with CPU and memory usage.
  2. Pipe to grep name to filter for a specific process.
  3. Use --sort=-%cpu or --sort=-%mem to find resource hogs.
  4. Use pgrep processname as a cleaner alternative to ps aux | grep name.

Frequently Asked Questions

What is the difference between ps and top?

ps takes a single snapshot of the process list at the moment it runs. top (and htop) provide a continuously updating interactive view. Use ps in scripts and one-time inspections; use top/htop for interactive real-time monitoring.

How do I kill a process found with ps?

Get the PID from the first column of ps output, then run kill PID to send SIGTERM (graceful shutdown) or kill -9 PID for SIGKILL (force kill). Use pkill processname to kill by name without needing the PID.

Why does my process not appear in ps aux?

If a process is not visible to your user, it may be running as a different user (use sudo ps aux) or it may have already exited. Zombie processes (Z state) appear in ps but have already terminated and are waiting for their parent to collect their exit status.

Related Tools