How to Kill All Python Processes in Ubuntu

By Kristen Waters

Running multiple instances of Python makes finding each individual instance difficult if you want to stop them. In Ubuntu Linux, each instance of an application or process has a unique ID. You can stop all instances of a particular process, such as Python, without knowing the ID of each process by using the "pkill" command, which locates all the processes that match your criteria and kills each one. The "pgrep" command outputs the process IDs based on the criteria given.

Step 1

Right-click the desktop and choose the **Terminal** option to open a terminal window.

Step 2

Type the command **sudo pkill python** to kill all the Python processes running, regardless of the user who started the process. Type your password when prompted.

Step 3

Type the command **sudo pgrep python** to ensure all Python processes have stopped. This command should not produce an output, and you will not be prompted for a password.

Tips & Warnings

  • The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Always use the -f option to match against the complete command line, /proc/pid/cmdline.

References & Resources