Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing which python process to kill on linux?

Tags:

python

linux

I've run a python script on the command line that can't be killed with ctrl-C (SIGINT).

 $ ./bad_script.py
 ^CTraceback(most recent call last):
 ...
 KeboardInterrupt
 ^C
 ^C
 ...
 <I give up>

When I look for this python process on another command line I see many options:

 $ pidof python
 1111 2222 3333 4444 5555 6666   # Which one is bad_script.py?

I want to kill my bad_script.py process, not the innocents.

Note this is not a duplicate of other questions that are similar because I want to know which process to kill:

  • OSX Terminal: How to kill all processes with the same name
  • Kill a python process
  • Kill python process with pkill python
like image 531
user79878 Avatar asked Sep 02 '26 09:09

user79878


1 Answers

You have a number of options. For example you can run the following ps command to list all running programs and use grep:

ps aux | grep bad_script

or if you have access to the source code, you could print the process id inside the script, at the start of the program:

import os
print os.getpid()

or just press Ctrl-\ to kill it in a different way by sending the SIGQUIT signal.

like image 136
JuniorCompressor Avatar answered Sep 03 '26 23:09

JuniorCompressor