User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Killing python script in background

Thu Jun 23, 2016 7:47 am

Greeting,
what is the way I could kill python script that raises on reboot or restart, (Raspbian Jessie)?
Startup goes to location /home/pi/.config/autostart and over myPiAutostart.desktop script opens python script.
The desktop file contains:
[Desktop Entry]
Type = Application
Name = MyPiAutostart
Exec = sudo python2 /home/pi/myPiConfig/checkGPIOstatus.py
StartupNotify = false
Name [hr_HR] = MyPiAutostart

I tried starting in the background with & symbol: Exec = sudo python2 /home/pi/myPiConfig/checkGPIOstatus.py &

How can I kill a script that is active in the background if I have a need sometimes to kill?
I cant even know PID for killing, task manager does not show my script in back processes...

Thanx in advance,
Faramon

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Killing python script in background

Thu Jun 23, 2016 7:50 am

ps axOT
will show all processes sorted by time
sudo kill -9 PID of the offending script
if you have a looped process .... i.e. a script that calls the program repeatedly on exit then kill that process first then the one you want
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Killing python script in background

Thu Jun 23, 2016 7:55 am

From a terminal

ps aux | grep python

should show the PID.

Alternatively

sudo killall python2

will kill all Python scripts started with the command python2.

User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Re: Killing python script in background

Thu Jun 23, 2016 8:08 am

Yes, i do have LOOP in python script.

I'll try your solution...

User avatar
faramon
Posts: 123
Joined: Sat Jun 11, 2016 8:36 am
Location: Croatia

Re: Killing python script in background

Thu Jun 23, 2016 8:17 am

I try
ps aux | grep python
and i found in given processes my PID.

Then in terminal i try
sudo kill -9 MyPID
and this works, thanx.

I did not try second given solution but thanx, someone maybe found it usefull.

Thanx,
Faramon

Return to “General discussion”