How to Kill a Process by Name in Linux Using pkill

When a program freezes in Linux, you need to force it to close. The traditional way to do this is a two-step process: first, you use the top or ps command to manually hunt through hundreds of running processes to find the specific Process ID (PID) number of the frozen app. Then, you use the kill command followed by that number.

This is slow and tedious. If you already know the name of the program that crashed (for example, Firefox or Apache), you can skip the PID hunt entirely and instantly terminate it using the pkill command.

How to Use pkill

The pkill command allows you to send a termination signal to a process using its human-readable name instead of its arbitrary numerical ID.

Syntax: pkill [process_name]

If your Firefox web browser is completely frozen and unresponsive, simply open your terminal and type:

pkill firefox

Press Enter, and the operating system will instantly hunt down any process with “firefox” in its name and gracefully shut it down.

The Danger of pkill (Pattern Matching)

While pkill is incredibly fast, it is also slightly dangerous because it uses pattern matching. It does not require an exact, perfect match to kill a program; it will kill anything that contains the word you typed.

For example, if you type pkill fire, Linux will kill the firefox web browser, but it will also kill a background process named firewall-daemon. If you are not careful with your spelling, you can accidentally take down critical system services.

How to Force Kill an Unresponsive Process

When you run a standard pkill firefox, Linux sends a polite “SIGTERM” signal to the application, asking it to please shut down and save its data.

If the application is violently crashed, it might ignore this polite request and remain frozen on your screen.

If you need to instantly and mercilessly execute a program without giving it a chance to protest, you must add the -9 flag (which sends the SIGKILL signal).

pkill -9 firefox

This command bypasses the application entirely. The Linux kernel simply cuts off the program’s memory access and drops it instantly. Use this only as a last resort, as any unsaved data within that application will be permanently lost.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

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

Receive our best articles and tips delivered straight to your inbox.