Dec-15-2017, 11:49 AM
Hello everyone,
my goal is to write a small service, which waits for another process to terminate and then shuts down the RPi.
Just like this:
The user clicks a button in the program, which closes it. Then my RPi shall shutdown.
(here the User actually wants to shutdown the VM by clicking "Shut down" in the Startmenu in Windows,
this terminates two processes on the RPi, but does not shutdown the RPi <-- that´s where my Service shall help)
Therefore i need something that waits for the process to terminate.
Which possibilities do i have here?
The solution i got uses the pid of the running program and checks every 60sec whether the path /proc/'pid' still exists.
If not ---> shutdown
If yes ---> repeat
A disadvantage of this method is that the worst case is a shutdown 60sec after the program has been closed.
Another is that it might be computational intensive if i repeat this every 3sec. Or is it not?
However...this is my stuff so far:
-Is this method i use here alright?
-If yes: is there something that can be improved?
-If not: what methods can you suggest?
The RPi will be running around 8hours/day and only work as thin-client
(so vmware-view is the only program users actually use...they won´t even realize it is linux)
The only moment my program should not be working is before the user logs in.
hhh
my goal is to write a small service, which waits for another process to terminate and then shuts down the RPi.
Just like this:
The user clicks a button in the program, which closes it. Then my RPi shall shutdown.
(here the User actually wants to shutdown the VM by clicking "Shut down" in the Startmenu in Windows,
this terminates two processes on the RPi, but does not shutdown the RPi <-- that´s where my Service shall help)
Therefore i need something that waits for the process to terminate.
Which possibilities do i have here?
The solution i got uses the pid of the running program and checks every 60sec whether the path /proc/'pid' still exists.
If not ---> shutdown
If yes ---> repeat
A disadvantage of this method is that the worst case is a shutdown 60sec after the program has been closed.
Another is that it might be computational intensive if i repeat this every 3sec. Or is it not?
However...this is my stuff so far:
import subprocess from subprocess import check_output import os import time def get_pid(name): try: return int(check_output(["pidof","-s",name])) #returns PID of vmware-view except subprocess.CalledProcessError, e: process_id = -1 #"-1" never exists! while True: time.sleep(60) process_id = get_pid("vmware-remotemks") if (type(process_id) != int): process_id = get_pid("vmware-remotemks-container") process_folder = "/proc/"+str(process_id) #process_id becomes filepath if (os.path.exists(process_folder) == False): os.system('shutdown -h now') #reboot RPiSo my actual questions are:
-Is this method i use here alright?
-If yes: is there something that can be improved?
-If not: what methods can you suggest?
The RPi will be running around 8hours/day and only work as thin-client
(so vmware-view is the only program users actually use...they won´t even realize it is linux)
The only moment my program should not be working is before the user logs in.
hhh