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

Kill process

Mon Oct 17, 2016 5:22 pm

Hi,
How t kill process in Raspbian Jessie with PIXEL?
I have a desktop script MyPiAutostart.desktop with content:

Code: Select all

[Desktop Entry]
Type=Application
Name=MyPiAutostart
Exec=sudo python2 /home/pi/myPiConfig/PirMotionDetected.py
StartupNotify=false
Name[hr_HR]=MyPiAutostart
This script starts with reboot or start of raspberry pi.
Script is in /home/pi/.config/autostart and if I reboot computer i found process in Task manager. If I terminate or kill this process from task manager, it disappear for a few moments and came up again and continues to work. Why I cannot kill this process, it raise again and again in task manager?
I create script for killing but unsuccessfully.
Script is:

Code: Select all

import subprocess
import RPi.GPIO as GPIO

GPIO.setwarnings(False) 
GPIO.setmode(GPIO.BCM)

PIR_PIN = 7 #GPIO7
GPIO.setup(PIR_PIN, GPIO.IN)
GPIO.cleanup()

proc = subprocess.Popen(["pkill", "-f", "PirMotionDetected.py"], stdout=subprocess.PIPE)
proc.wait()
Haw can I kill process?

Thanx,
Faramon

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Kill process

Mon Oct 17, 2016 7:29 pm

faramon wrote:Script is in /home/pi/.config/autostart and if I reboot computer i found process in Task manager. If I terminate or kill this process from task manager, it disappear for a few moments and came up again and continues to work. Why I cannot kill this process, it raise again and again in task manager?
You left out the code in the autostart file. It is supposed to restart if you prefix the command with the @ symbol and not do so otherwise. Did you prefix your command with the @ symbol? There have been what I think are bugs in the implementation of autostart stuff in lxde, so anything is possible, did you use the @ prefix?

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

Re: Kill process

Mon Oct 17, 2016 7:36 pm

My code is without @ and looks like

Code: Select all

[Desktop Entry]
Type=Application
Name=MyPiAutostart
Exec=sudo python2 /home/pi/myPiConfig/PirMotionDetected.py
StartupNotify=false
Name[hr_HR]=MyPiAutostart

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Kill process

Mon Oct 17, 2016 7:40 pm

faramon wrote:My code is without @ and looks like

Code: Select all

[Desktop Entry]
Type=Application
Name=MyPiAutostart
Exec=sudo python2 /home/pi/myPiConfig/PirMotionDetected.py
StartupNotify=false
Name[hr_HR]=MyPiAutostart
I'm talking about the ~/.config/lxsession/LXDE/autostart which in default looks something like:

@lxpanel --profile LXDE
@pcmanfm --desktop --profile LXDE
@xscreensaver -no-splash

Did you add your program to that file?

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

Re: Kill process

Mon Oct 17, 2016 7:46 pm

No. I just put my desktop file in /home/pi/.config/autostart

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Kill process

Mon Oct 17, 2016 8:04 pm

Your autostart runs the python script with sudo so only root can kill the process. As far as I'm aware TaskManager can only kill processes that the current user owns, asking it to kill a process owned by root will just give you an error message.

Your other python script should be able to kill the first process as long as it is also run with sudo, or you could just run

Code: Select all

sudo pkill -f PirMotionDetected.py
from the command line.
She who travels light — forgot something.

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

Re: Kill process

Mon Oct 17, 2016 8:22 pm

thanx,
I think you have right. I will try kill the script with sudo command or remove sudo from desktop script.
Faramon

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

Re: Kill process

Tue Oct 18, 2016 3:51 pm

Hi,

I remove sudo from desktop script and now I can Terminate process from Task manager.
This works great, thanx.
Faramon

Return to “General discussion”