Kill process(es) of a running script
I've created a script
Code:
#!/bin/bash This program consumes a lot of CPU (as its just sits in a loop awaiting changes) and I'd like to kill it when I finished. Looking at ps aux I've got these 3 lines /bin/bash ./sgh (the name of the script file) sudo python scratch_gpio_handler.py python scratch_gpio_handler.py My question is do I have to kill all three or can I get away with just killing the last one? regards Simon |
You can kill the first one and it should reap the child processes along with it.
|
Killing the first one only doesn't seem to work for me - the others seem to stay running.
Killing the last one seems to remove all of them but I can't work out the syntax to supply to pkill Code:
sudo pkill python Any suggestions please? regards Simon |
You will need to find the parent process and kill that, it will then reap the child processes. The .sh process is usually the parent process.
A ps aux | grep python will give you the process numbers as well as the PPID(parent process ID). You can then check that PPID and kill it. |
As I said, killing the bin/bash process doesn't seem to kill the other two for me.
But killing the python scratch_gpio_handler.py process does seem to kill all the others as well. But my problem now is that I can't work out the syntax to kill that one :( Simon |
you Can try these
Quote:
|
Quote:
|
Code:
sudo ps aux | grep "python scratch_gpio_handler.py" | grep -v grep | awk '{print $2}' | xargs sudo kill -9 Thanks for the help people :) Simon |
Good code cymplecy, you are limiting your grep to a specific process that way instead of killing all python processes. The one killing all python could do something like kill yum during a transaction and bork your rpmdb as well as yum.
|
All times are GMT -5. The time now is 05:39 PM. |