The ps Command — Viewing and Analyzing Processes in Linux¶
The
ps(Process Status) command is one of the most important Linux utilities for viewing running processes. It provides detailed information about process IDs (PIDs), users, CPU usage, memory consumption, parent-child relationships, process states, and running commands. Every Linux administrator, DevOps engineer, SRE, and Cloud Architect usespsdaily for troubleshooting and system monitoring.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
pscommand - Display running processes
- Interpret
psoutput - View process ownership
- Filter processes
- Display process hierarchy
- Customize process information
- Troubleshoot production applications
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management and Permissions
- Module 5 – Users and Groups
- Module 6 Lessons 1–2
Why Learn the ps Command?¶
Imagine a production application stops responding.
Questions:
- Is the application running?
- What is its PID?
- Who owns the process?
- How much CPU is it using?
- Is it stuck?
The first command most Linux administrators use is:
What is ps?¶
ps stands for:
Process Status
It displays information about running processes.
Unlike top, ps shows a snapshot of the processes at the moment you execute the command.
Basic Usage¶
Example:
By default, it displays processes associated with the current terminal.
Display All Processes¶
or
Example:
Full Process List¶
Example:
BSD Style Output¶
Linux also supports BSD-style options.
Example:
Unlike ps -ef, BSD-style options omit the leading hyphen.
Understanding ps -ef Output¶
| Column | Description |
|---|---|
| UID | Process owner |
| PID | Process ID |
| PPID | Parent Process ID |
| C | CPU scheduling value |
| STIME | Start time |
| TTY | Terminal |
| TIME | CPU time used |
| CMD | Command |
Display Process Tree¶
or
Example:
Display Process State¶
Example:
Display Specific Process¶
Using a PID.
Example:
Multiple PIDs.
Display Processes by User¶
Example:
Display all processes owned by root.
Filter Using grep¶
Example:
Find Docker.
Find Java.
Custom Output¶
Show PID, user, and command.
Show CPU and memory usage.
Show elapsed running time.
Sort Processes¶
Sort by CPU.
Sort by memory.
Display the top 10 CPU consumers.
View Parent-Child Relationship¶
Observe:
This helps identify process hierarchies.
Common Commands¶
Basic process list.
All processes.
Detailed view.
BSD format.
Single process.
By user.
Real Production Examples¶
Check NGINX.
Check Kubernetes.
Check Docker.
Check PostgreSQL.
Check Java application.
Production Perspective¶
The ps command is used extensively for:
- Troubleshooting applications
- Identifying running services
- Monitoring process ownership
- Finding PIDs
- Preparing to terminate processes
- Capacity planning
- Performance analysis
It is one of the first commands used during production incident investigations.
Hands-on Lab¶
Task 1¶
Display your terminal processes.
Task 2¶
Display all processes.
Task 3¶
Display BSD format.
Task 4¶
Display PID 1.
Task 5¶
Display process states.
Task 6¶
Display your own processes.
Task 7¶
Search for SSH.
Task 8¶
Display the top CPU-consuming processes.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
ps | Current terminal processes | Daily usage |
ps -ef | Full process list | Troubleshooting |
ps aux | BSD-style process list | Monitoring |
ps -p | Specific PID | Process verification |
ps -u | User processes | User audits |
ps -eo | Custom output | Reporting |
Production Troubleshooting Scenario¶
Scenario
Users report that the company web application is unavailable.
Investigation:
Findings:
- NGINX is running.
- The backend Java application is missing.
Next steps:
- Review application logs.
- Restart the backend service if appropriate.
- Investigate why the process terminated unexpectedly.
The ps command quickly confirms whether critical services are running before deeper troubleshooting begins.
Best Practices¶
- Use
ps -effor detailed process information. - Use
grepto locate specific processes. - Verify the process owner before taking action.
- Use custom output (
ps -eo) when creating reports. - Combine
pswith other monitoring tools such astopandsystemctlfor comprehensive diagnostics.
Common Mistakes¶
❌ Assuming a service is running without verifying it.
✅ Verify a service is running without verifying it instead of assuming it.
❌ Killing the wrong process because the PID was not checked carefully.
✅ Avoid this mistake: killing the wrong process because the PID was not checked carefully.
❌ Forgetting that ps displays a snapshot, not a live view.
✅ Use top or htop for real-time monitoring.
Interview Questions¶
Beginner¶
- What does
psstand for? - What is the difference between
psandps -ef? - Which command displays all running processes?
- How do you display a specific PID?
Intermediate¶
- What is the difference between
ps -efandps aux? - How do you display processes owned by a specific user?
- How do you sort processes by CPU usage?
- Why is the PPID important?
Architect Level¶
- How would you investigate whether an application is still running?
- How do you identify orphaned or unexpected processes?
- Why is
psan important tool during production incident response?
Summary¶
In this lesson, you learned:
- The
pscommand - Viewing running processes
- Understanding PID and PPID
- Process ownership
- Filtering processes
- Custom output
- Process hierarchy
- Production troubleshooting
The ps command is one of the most fundamental Linux administration tools. It provides a detailed snapshot of the system's running processes and is indispensable for troubleshooting, monitoring, and managing production workloads.
Key Takeaways¶
psdisplays a snapshot of running processes.- Use
ps -effor detailed process information. - Use
ps auxfor BSD-style output. - Use
ps -pto inspect a specific process. - Use
ps -uto display processes for a user. - Combine
pswithgrepto quickly locate specific applications.
What's Next?¶
The top Command — Real-Time Process Monitoring in Linux
You'll explore:
- Real-time process monitoring
- CPU and memory utilization
- System load
- Interactive process management
- Sorting processes
- Performance troubleshooting
The top command provides a live view of your Linux system and is one of the most valuable tools for diagnosing performance issues in production environments.