I'm making gpio scripts on my rpi and I want a core program to run and kill another python script.
I had some trouble to find an explanation on how to do this but finally went for this solution : How to terminate a python subprocess launched with shell=True. So my code is :
# // on button pressed, turn on the lcd
spawnProcess = subprocess.Popen("python jukebox_lcd.py", shell=True, preexec_fn=os.setsid)
print "pid : ", os.getpgid(spawnProcess.pid)
# // off button pressed, turn off the lcd
os.killpg(os.getpgid(spawnProcess.pid), signal.SIGTERM)
It will return for example pid : 5030 but will not turn off the lcd... The process I need to kill is 5031 :
    volumio@volumio:~$ ps -elf | grep python
4 S root      4991  2760  0  80   0 -  1307 -      23:11 pts/0    00:00:00 sudo python jukebox-buttons.py
4 S root      4995  4991  3  80   0 -  8352 -      23:11 pts/0    00:00:00 python jukebox-buttons.py
0 S root      5030  4995  0  80   0 -   456 -      23:11 ?        00:00:00 /bin/sh -c python /home/FTP/jukebox_lcd.py
0 S root      5031  5030  1  80   0 -  2062 -      23:11 ?        00:00:00 python /home/FTP/jukebox_lcd.py
0 S volumio   5035  3952  0  80   0 -   648 pipe_w 23:11 pts/1    00:00:00 grep python
I don't understand why my subprocess runs "/bin/sh -c python myscript" and how to fix this. Any help please?
 
    