@tictac_93 This works in most cases ... yes
But look. You take PID of runcommand and use pkill -P switch to kill child PID. That works in most cases but some emulators also just call annother process and this won't be catched by your method. You need at least annother pkill -P call.
You should just use your python script and you can use the multi_switch and it's command line options. Therefore use a python call like output = int(subprocess.check_output(['./multi_switch.sh', '--es-pid'])) and you can check if ES is running. If the ouput is 0 then python interprets this as false if a PID is detected the value is grater than 0 - this interprets python as true.
So the sniplet in python itself would be look like this.
if output:
os.system("./multi_switch.sh --es-poweroff")
else:
os.system("sudo shutdown -h now")