Day 15 - Master Process Termination Using ps, grep, awk, and xargs


๐ง Day 15 of my DevOps journey focused on managing running processes. I learned to find and kill Apache HTTPD processes using command-line tools like ps
, grep
, awk
, and xargs
.
๐ Step-by-Step Process Management
โ 1. List All Running Processes
ps aux # Detailed view (username, PID, %CPU, command)
ps -ef # Full-format listing (UID, PID, PPID, etc.)
๐ 2. Filter Apache Processes
ps -ef | grep httpd
ps -ef | grep httpd | grep -v 'grep'
grep -v 'grep'
removes the grep command from the result.
โ 3. Kill a Single Process
kill 1420
kill -9 1476 # Force kill
๐ 4. Kill All httpd
Processes at Once
ps -ef | grep httpd | grep -v 'grep' | awk '{print $2}' | xargs kill -9
Here's what each part does:
ps -ef
โ list all processesgrep httpd
โ search for Apache processesgrep -v grep
โ exclude grep itselfawk '{print $2}'
โ extract the PID (process ID)xargs kill -9
โ forcefully kill each PID
๐ 5. Restart Apache
systemctl start httpd
Then verify again:
ps -ef | grep httpd | grep -v grep
๐ง What I Learned
โ
How to find processes using ps
โ
Use grep
, awk
, xargs
to dynamically extract and act on data
โ
Kill processes by PID or in batch
โ
Restart services after killing
โ
Useful for troubleshooting stuck or zombie services in production
๐ ๏ธ Real-World Application
This is critical knowledge for DevOps engineers when:
Dealing with rogue or hanging processes
Managing servers without a GUI
Writing shell scripts to automate process handling
๐ฎ What's Next?
Day 16 will focus onArchiving Jenkins Logs with tar, zip & unzip
Subscribe to my newsletter
Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
