How to Kill Processes by Name Using the pkill Command in Linux

When a rogue script, a memory leak, or a catastrophic system error spawns multiple instances of the same process on a Linux server, identifying every single numerical Process ID (PID) to terminate them individually is a catastrophic waste of time. To force the Linux kernel to algorithmically scan the process matrix and violently terminate every instance of a program based exclusively on its text-based name, you must deploy the pkill command.

Executing the Name-Based Termination Engine

The standard kill command strictly requires numerical PIDs. The pkill (Process Kill) command acts as a highly optimized regex wrapper around the termination engine. It ingests a text string (the name of the rogue application), scans the active process table, matches the string against all running processes, and mathematically executes the termination signal against every single match simultaneously.

Executing a Basic Process Purge

Imagine a rogue Python script named data_miner.py has spawned 15 frozen instances, completely consuming your CPU cycles.

To execute the termination protocol, open your terminal and type:

pkill data_miner.py

The exact millisecond you press Enter, the pkill engine rips through the process table. It sends the standard SIGTERM (Signal 15 – Terminate) to every single process matching the exact string data_miner.py, requesting a clean, mathematical shutdown.

Executing an Aggressive Kill Vector

If the rogue processes are completely frozen and unresponsive to the polite SIGTERM request, you must force the engine to escalate to absolute violence. You can inject the -9 flag to send the SIGKILL (Signal 9) vector.

pkill -9 data_miner.py

The engine will bypass the process’s internal logic and command the Linux kernel itself to instantly vaporize the process from RAM without warning or cleanup.

CRITICAL SYSTEM WARNING: The pkill engine uses partial string matching by default. If you execute pkill ssh, it will violently terminate ssh, but it will also terminate sshd (the daemon keeping your remote connection alive). To force the engine to only kill processes where the name is an exact, absolute match, you must inject the -x flag: pkill -x ssh.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.