25 Useful 'ps Command' Examples for Linux Process Monitoring

The ps command is a powerful tool used for monitoring processes in Linux operating systems. It stands for process status and displays information about processes currently running on a system. This information is useful for troubleshooting, optimizing performance, and identifying potential security issues. Below are 25 useful ps command examples for effective Linux process monitoring.

Basic Process Listing

Display All Running Processes

ps aux

This displays all processes with detailed information including PID (process ID), CPU usage, memory usage, user, and command.

Show Process Tree Structure

ps auxf

The f flag shows processes in a tree-like structure, making parent-child relationships clear.

Sorting and Filtering Options

Sort by CPU Usage

ps aux --sort=-%cpu

Lists all processes sorted by CPU usage in descending order, showing the most CPU-intensive processes first.

Sort by Memory Usage

ps aux --sort=-%mem

Displays processes sorted by memory consumption in descending order.

Filter by User

ps -u username

Shows only processes owned by the specified user. Replace username with the actual username.

Filter by Command Name

ps -C command_name

Displays processes running a specific command. Replace command_name with the desired command.

Terminal and Process Group Filtering

Show Processes for Specific Terminal

ps -t pts/0

Lists processes running in a specific terminal. Replace pts/0 with your terminal identifier.

Filter by Process Group

ps -g pgid

Shows processes in a specific process group. Replace pgid with the process group ID.

Show Child Processes

ps --ppid 1234

Displays child processes of a specific parent process. Replace 1234 with the parent process ID.

Advanced Filtering Techniques

Find Zombie Processes

ps aux | awk '$8=="Z" {print}'

Zombie processes are those that have finished executing but haven't been cleaned up by the system. They appear with state "Z".

Filter by Process State

ps -eo state,pid,user,command | grep "R"

Shows processes in a specific state. Common states: R (running), S (sleeping), Z (zombie), D (uninterruptible sleep).

View Process Priorities

ps -o pid,ppid,user,nice,cmd --sort=-nice

Displays processes sorted by priority (nice value) in descending order.

Show CPU Affinity Information

ps -eo pid,psr,pcpu,comm --sort=-pcpu

Shows which CPU core each process is running on along with CPU usage percentage.

Network and File Usage Monitoring

Find Processes Using Specific Port

sudo lsof -i :8080

Lists processes using port 8080. Replace with your desired port number.

Show All User Processes

ps -U username -u username u

Comprehensive view of all processes for a specific user.

Find Processes in Directory

lsof +D /var/log

Shows processes accessing files in the specified directory.

List Processes Using Executable

ps -C firefox

Displays all instances of a specific executable.

Find Processes Using File

lsof /var/log/syslog

Shows which processes are accessing a specific file.

Custom Output Formats

Filter by Environment Variable

ps -eo pid,user,args | grep "PATH="

Finds processes with specific environment variables in their command line.

Monitor Network Interface Usage

sudo lsof -i -n -P | grep eth0

Shows processes using a specific network interface.

Custom Format Display

ps -eo pid,user,%cpu,%mem,command --sort=-%mem | head -10

Custom format showing top 10 memory-consuming processes.

View Process Memory Map

sudo pmap -x 1234 | grep heap

Examines memory segments of a specific process. Replace 1234 with the process ID.

High Resource Usage Filter

ps -eo pid,user,%cpu,%mem,command | awk 'NR==1 || $3>=5.0'

Shows processes using more than 5% CPU, including the header.

Process Tree Visualization

Display Process Tree

pstree -p

Shows a hierarchical tree view of all processes with their PIDs, making parent-child relationships clear.

Real-time Process Updates

watch -n 2 'ps aux --sort=-%cpu | head -10'

Updates the top 10 CPU-consuming processes every 2 seconds for real-time monitoring.

Practical Monitoring Examples

Use Case Command Description
Memory Leaks ps aux --sort=-%mem | head -10 Find top memory consumers
CPU Intensive Tasks ps aux --sort=-%cpu | head -10 Identify high CPU usage
User Activity ps -u username -o pid,cmd Monitor specific user processes
System Services ps -ef | grep -E "(systemd|init)" View system service processes

Conclusion

The ps command is an essential tool for Linux system administration and process monitoring. These 25 examples demonstrate various filtering, sorting, and formatting options that help identify system bottlenecks, monitor resource usage, and troubleshoot performance issues effectively. Mastering these commands enables better system management and proactive problem resolution.

Updated on: 2026-03-17T09:01:38+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements