Understanding process management is crucial for Linux system administration. This guide covers essential commands for monitoring and controlling processes.
Table of Contents
Open Table of Contents
Viewing Processes
Using ps Command
ps aux
Output:
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 225868 9288 ? Ss Oct30 0:08 /sbin/init
user 2451 0.1 0.2 3246504 42716 ? Sl 10:00 0:12 firefox
Process Tree View
pstree
Process Monitoring
Using top Command
top
Output:
top - 12:00:00 up 2 days, 3:45, 2 users, load average: 0.52, 0.58, 0.59
Tasks: 180 total, 1 running, 179 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.9 us, 2.3 sy, 0.0 ni, 91.4 id, 0.3 wa, 0.0 hi, 0.1 si
MiB Mem : 15951.3 total, 7855.5 free, 4589.2 used, 3506.6 buff/cache
Interactive Quiz
Question 1
What command would you use to find the PID of a specific process?
Click to see answer
pgrep process_name
# or
ps aux | grep process_name
Question 2
How do you terminate a process gracefully?
Click to see answer
kill -15 PID
# or
killall process_name
Process Control
Kill Commands
kill -9 1234 # Force kill
kill -15 1234 # Graceful termination
killall firefox # Kill all Firefox processes
Process Priority
nice -n 10 command # Start with lower priority
renice +5 -p 1234 # Change priority
Best Practices
- Always try graceful termination first
- Monitor system resources regularly
- Use appropriate nice values
- Document critical processes
- Set up process monitoring
Troubleshooting
Common Issues and Solutions
# Find zombie processes
ps aux | grep 'Z'
# Kill unresponsive process
kill -9 $(pgrep unresponsive_app)
Conclusion
Process management is essential for maintaining a healthy Linux system. Regular monitoring and proper control ensure optimal system performance.
What’s Next in the Series?
- Text Processing with Grep and Sed
- Network Commands Guide
- System Monitoring Tools
- Bash Scripting Basics