Linux Commands

How To Kill All Python Processes in Linux

There is always the need to remove any process or program running, whether it is Windows or Linux. This is very common because any process uses specific memory of that ‌operating system when it is in running condition. Once the process is completed, it is necessary to remove that process.

In Linux, there are several ways to kill a process, but many people are unfamiliar with it. If you use Python regularly, you must know how to kill the process quickly. This guide will explain how to kill all Python processes in Linux.

How To Kill All Python Processes in Linux

We will mainly use killall and pkill commands to kill all Python processes in Linux. These commands terminate or kill the group of any running process based on its given name and other attributes.

Pkill Command

The pkill command is part of the procps-ng or props package, pre-installed on almost all Linux distributions. This command-line utility helps you kill the running program’s processes by sending signals based on the parameters provided. Here, you can specify any process by its partial or full name or other attributes. It is very easy to delete any group of processes through this command.

Here, we will kill all the Python processes with the pkill command. So, run the following command to kill the Python processes:

sudo pkill python

Once you enter the previous command, it will ask you for your root password. As soon as you enter the password, it will immediately wipe out all Python processes and stop the same processes.

Killall Command

The killall command also works similarly to the pkill command. This command-line utility is also straightforward to use. All you have to do is pass the process name or other attributes as arguments to killall.

Here, we will remove all Python processes using the killall command. Run it in the terminal by adding the name of the process you want to delete with the killall command. We will kill all the Python processes by running the following command:

killall python

After running the previous command in the terminal, you will go to the screen of that process and see that your running process has been killed. As you can see, your running Python process is “Terminated” by running the previous command.

Conclusion

In this guide, we have explained how to kill all Python processes in Linux. We terminate a group of Python processes using the “pkill” and “killall” command-line utilities. The similar unique feature between these two command-line utilities is that they can kill a group of processes without the PID number based on the process name. As we have seen, they are effortless to perform, and we can quickly and easily kill a bunch of Python processes.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.