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 processes

  • grep httpd โ€” search for Apache processes

  • grep -v grep โ€” exclude grep itself

  • awk '{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

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir