简单的应用程序监听程序,若被监听的程序崩溃会自动重启,类似Unix/Linux命令screen
目的:为该死的Windows而作
运行环境:Python
source code:
#!/usr/bin/python
import psutil
import os
import threading
import time
# you case applictions
processs = {
"game_server_d.exe": "D:\\ghoul_app\\game_server\\",
}
# watch interval(s)
interval = 2
def recordLog(log):
filename = "watch.log"
with open(filename, "a") as fp:
print(log)
fp.write(log)
fp.write("\n")
def isRunning(path, process_name):
try:
pids = psutil.pids()
for pid in pids:
p = psutil.Process(pid)
# print("pid-%d, pname-%s" % (pid, p.name()))
try:
if p.name() == process_name and p.cwd() == path:
return True