3

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:

Community
  • 1
  • 1
user79878
  • 775
  • 9
  • 13
  • 2
    `pps aux | grep bad_script | awk '{print $2}'` – Padraic Cunningham Apr 30 '15 at 19:15
  • 2
    Normally I do `ctrl-z` and then use `kill -9 %1` to kill the process in bash via its job number. – Dan D. Apr 30 '15 at 19:16
  • 1
    Press `C-Z` to stop it, then use your shell's kill: `kill %`. This way, you won't miss. – Petr Skocik Apr 30 '15 at 19:17
  • 1
    Did you run the script from a different tty (window) than the other scripts? You can (sometimes) examine the the (pseudo)tty to find and identify the correct process (pid) (unless you started most/all processes from the same terminal/tty/window). – ChuckCottrill May 01 '15 at 01:18
  • 1
    The age of the process can be an indication of which process (unless you started them all at the same time. – ChuckCottrill May 01 '15 at 01:18
  • Can you identify from the command line arguments? You might be able to use the /proc virtual filesystem to examine the command line arguments, ex: cat /proc//cmdline – ChuckCottrill May 01 '15 at 01:21
  • Or you could send SIGSTOP to each process until you find the one you want to stop, and selectively restart the ones you want to keep by sending SIGCONT – ChuckCottrill May 01 '15 at 01:23

1 Answers1

2

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.

JuniorCompressor
  • 19,631
  • 4
  • 30
  • 57