php - How can I kill a process as user www-data -


i start python file via webpage user www-data. how can kill process @ later time running different python script?

my php webpage contains code start process:

echo shell_exec("sudo python /home/pi/desktop/picontrol/motion_sensor.py"); 

method 1 (this answers question on title):

let www-data admin in server.

adduser www-data sudo 

then remove sudo password while executing commands

reference: execute sudo without password?

sudo visudo 

in bottom of file, type follow:

www-data all=(all) nopasswd: 

note: there high security risk, hackers may shutdown server, can imagine server! @ own risk

method 2:

write service(with other php or python) , run root/admin user, once it's called, kill python on server.

method 3:

a stupid method: let python create empty file on start up, set file permission 777 user can delete it. check if file exist every 5 seconds, if not exist, exit itself.

finally, if want stop python, let php delete file.

method 4:

i noticed, www-data run python script itself, why not can't kill it? have try.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -