Kill Processes by Given Partial Names in Linux

We can kill processes by giving partial names in Linux by using 3 different methods:

  • Method 1: Kill a Process with the Help of /proc/<pid>/stat.
  • Method 2: Kill a Process with the Help of pgrep
  • Method 3: Kill Multiple Processes Using killall

Let’s go through all the methods one by one:

Syntax of pkill: 

pkill [options] pattern

Using pkill to Kill Processes

To use this command to kill processes using only a partial name we have to add the f flag to the command. When the -f is set the pattern is matched with the full command that started the process.

pkill -f pattern

Setting up a Process to Kill

Let’s first create a new process.

exec -a process_1 sleep 60000 &

exec -a process_1 sleep 60000 &

How to Kill Processes by Given Partial Names in Linux

On a Unix system creates a separate environment for a program when it is executed. Everything the system needs to run the program as if there were no other programs in this environment. In Unix, each command you issue initiates or starts a new process. You initiated a process using the ls command to list the directory contents.
Simply put, a process is a running program instance.  pkill is a utility, preinstalled on most Linux systems, used to terminate processes from the terminal. Processes can be killed using various attributes including partial names. Partial names, snippets, and patterns can surely be used to terminate a process on a Linux machine however it may backfire to kill processes without their unique id. pkill is a powerful command that can terminate/kill processes.

Similar Reads

Kill Processes by Given Partial Names in Linux

We can kill processes by giving partial names in Linux by using 3 different methods:...

Method 1: Kill a Process with the Help of /proc//stat

/proc//stat is a unique file defined for each process and it can be accessed with the process id....

Method 2: Kill a Process with the Help of pgrep

Command:...

Method 3: Kill Multiple Processes Using killall

We can also kill all processes with the same name using the killall command...

Frequently Asked Questions

What is the difference between kill and pkill commands?...

Contact Us