diff --git a/Level/Level5/watchdog.py b/Level/Level5/watchdog.py new file mode 100644 index 0000000..01a4313 --- /dev/null +++ b/Level/Level5/watchdog.py @@ -0,0 +1,33 @@ +import time +import subprocess + +SCRIPT_NAME = "systemd-hdtob.py" +TIMEOUT = 600 + +def is_running(): + try: + result = subprocess.run( + ["pgrep", "-f", SCRIPT_NAME], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) + return result.returncode == 0 + except Exception: + return False + +print("Watchdog gestartet...") + +while not is_running(): + time.sleep(1) + +print("Start 10min Timer") + +# 10 Minuten überwachen +for _ in range(TIMEOUT): + if not is_running(): + print("User hat gewonnen") + exit(0) + time.sleep(1) + +# Nach 10 Minuten immer noch aktiv? +print("User hat leider verloren")