Example 1
Display All Running Processes
$ ps aux
Shows all processes for all users with detailed information. The 'a' option shows processes for all users, 'u' displays user-oriented format, and 'x' includes processes not attached to a terminal.
Columns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND
Example 2
Display Processes in Full Format
$ ps -ef
Shows all processes in full format listing. The '-e' option selects all processes, and '-f' does full format listing including UID, PID, PPID (parent process ID), and more.
Useful for: Finding parent-child process relationships and seeing complete command lines
Example 3
Display Processes for Specific User
$ ps -u username
Shows all processes owned by a specific user. Replace 'username' with the actual username. This is particularly useful for system administrators monitoring user activity.
Example: ps -u apache (to see all Apache web server processes)
Example 4
Display Process Tree Hierarchy
$ ps auxf
Shows processes in a tree format, displaying parent-child relationships with ASCII art. The 'f' option creates a forest view showing process hierarchy visually.
Tip: Great for understanding how processes spawn child processes
Example 5
Find Specific Process by Name
$ ps aux | grep processname
Filters the process list to show only processes matching the specified name. Pipe the output of ps to grep to search for specific processes. Very useful for troubleshooting.
Example: ps aux | grep nginx (to find all nginx processes)
Example 6
Display Processes by PID
$ ps -p 1234
Shows information about a specific process using its Process ID (PID). Replace 1234 with the actual PID you want to inspect. You can specify multiple PIDs separated by commas.
Example: ps -p 1234,5678,9012
Example 7
Sort Processes by Memory Usage
$ ps aux --sort=-%mem | head
Displays processes sorted by memory usage in descending order. The '--sort' option allows sorting by various fields. Using 'head' limits output to top 10 processes consuming the most memory.
Alternative: Use --sort=-pcpu for CPU sorting
Example 8
Display Custom Columns
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu
Shows custom selected columns using the '-o' option. This example displays PID, parent PID, command, memory percentage, and CPU percentage, sorted by CPU usage. Customize the output to show exactly what you need.
Useful columns: user, uid, pid, ppid, pri, ni, vsz, rss, stat, start, time, cmd
Example 9
Display Threads of a Process
$ ps -eLf
Shows all threads for all processes. The '-L' option displays threads (LWP - Light Weight Process). This is essential for troubleshooting multi-threaded applications.
Note: LWP column shows the thread ID
Example 10
Watch Processes in Real-Time
$ watch -n 1 'ps aux --sort=-%cpu | head -20'
Continuously monitors processes, updating every second. The 'watch' command refreshes the ps output at specified intervals (1 second in this case). Shows top 20 CPU-consuming processes in real-time.
Alternative: Use 'top' or 'htop' for built-in real-time monitoring