4

I once asked for a script to control unity launcher auto-hide behavior and the community here was kind and clever enough to give me exactly what I needed here.

Now I wonder if there is ONE command to grep this running py script ID then kill it as I want to add two keyboard shortcuts to switch this script on and off.

2
  • Your other question is quite interesting. Don't mind if I try to write another solution for it ? Jul 12, 2016 at 19:41
  • yes sure. why not ?
    – Misho21
    Jul 12, 2016 at 21:32

1 Answer 1

5

Yes, pkill. If your script is named myPythonScript.py, you can run:

pkill -f myPythonScript.py

Note that that command will kill all running instances of myPythonScript.py. It will also kill any other process whose full commandline includes the string myPythonScript.py so, for example, it would kill your editor if you had launched it with something like emacs myPythonScript.py.

To be sure you kill only the running script, you can try matching the command more specifically:

pkill -f "/python.*myPythonScript.py"

That will only kill processes matching /python, 0 or more characters and the name of the script. Since the script will look like this in the list of processes:

terdon 20559  0.0  0.0  22768  7404 pts/4    S+   18:18   0:00 /bin/python /home/chapplec/scripts/myPythonScript.py

That should kill only running instances of the script.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .