DEV Community

Cover image for Killing Processes Gracefully with kill, pkill and killall
Sana Muhammad Sadiq
Sana Muhammad Sadiq

Posted on

Killing Processes Gracefully with kill, pkill and killall

Introduction

As I continue my 30-day Linux challenge in preparation for the RHCSA exam. Today is about something powerful yet surprisingly elegant: gracefully managing running processes in Linux. Each command, each concept is another step toward mastery.

Index

  1. What Happens When a Process Misbehaves
  2. kill
  3. pkill
  4. killall
  5. Real World Scenario
  6. Pro Tips
  7. Quick Summary

🚨 What Happens When a Process Misbehaves?

Sometimes, a process freezes, eats up memory, or refuses to quit. That’s where Linux gives us three mighty tools to step in with authority but grace too.

  • kill
  • pkill
  • killall

Let’s understand how each works.

🧰 kill 🗡️

The Precision Tool
kill is used to send signals to specific processes using their PID (Process ID).

kill -SIGTERM 1234
Enter fullscreen mode Exit fullscreen mode

Image description

This sends a polite request (SIGTERM) asking the process to stop. Want to force it?

kill -9 1234   # SIGKILL – Force kill if it's stubborn
Enter fullscreen mode Exit fullscreen mode

Image description

✅ Tip: Always try SIGTERM before using SIGKILL. Be kind to your processes!

🔍 pkill 🔠

The Pattern Matcher
Don’t want to look up PIDs? pkill lets you target processes by name or pattern:

pkill firefox
Enter fullscreen mode Exit fullscreen mode

Image description

This will gracefully terminate all processes with the name "firefox".

Need to be more specific?

pkill -u sana chrome
Enter fullscreen mode Exit fullscreen mode

Image description

This targets only Chrome processes run by user sana.

🧼 killall 🧹

The Sweeper Broom
Use killall to kill all instances of a process by name.

killall -15 node
Enter fullscreen mode Exit fullscreen mode

Image description

This sends SIGTERM to all "node" processes.

killall -9 node
Enter fullscreen mode Exit fullscreen mode

Image description

Force kill them if they don’t cooperate.

🎯 Real World Scenario

Imagine you’re deploying a Node.js server and something goes haywire. Rather than finding the exact PID:

killall node
Enter fullscreen mode Exit fullscreen mode

One command. All processes. Clean slate.

✨ Pro Tips

✅ Prefer SIGTERM over SIGKILL — it gives apps time to clean up.
✅ Use pgrep first to check what you're about to kill.
✅ Log process shutdowns in production environments.

🧩 Quick Summary

Learning to gracefully stop processes isn’t just about control — it's about respecting the system’s state, and ensuring stability with precision. And now you're confidently in control when it comes to managing Linux processes onwards and upwards.

Image description

I'd love to hear your thoughts, insights or experiences with Linux. Feel free to share and join the conversation [ Connect with me on LinkedIn www.linkedin.com/in/techwithsana ]💜

#30dayslinuxchallenge #redhat #networking #cloudcomputing #cloudengineer #cloudarchitect #cloud #RHCSA #RHCE #RHEL #WomeninTech #Technology

Top comments (0)