Process 用Python编写看门狗
我需要在UbuntuLTS上为第三方网络文件传输java程序编写一个看门狗,该程序每持续40-50分钟网络传输@4MB/s就会死掉一次 我不能修改那个java程序,但它是通过upstart生成的 我当前的看门狗正忙着等待:Process 用Python编写看门狗,process,signals,monitoring,watchdog,Process,Signals,Monitoring,Watchdog,我需要在UbuntuLTS上为第三方网络文件传输java程序编写一个看门狗,该程序每持续40-50分钟网络传输@4MB/s就会死掉一次 我不能修改那个java程序,但它是通过upstart生成的 我当前的看门狗正忙着等待: while monitoring_enabled: begin_time = now() # query ps and /proc to see if it's there end_time = now() diff_time = end_ti
while monitoring_enabled:
begin_time = now()
# query ps and /proc to see if it's there
end_time = now()
diff_time = end_time - begin_time
if not diff_time > sleep_time:
sleep(sleep_time - diff_time)
由于“忙等待是不好的”,而且这会占用约10%的CPU,我想知道是否有更好的方法来解决这个问题:
编写bash脚本以在while循环中运行程序
#!/bin/bash
while true; do
java -jar offendingProgram.jar
done
然后将脚本从您启动它的任何地方加载。-Python、生成和控制进程、事件通知、xml-rpcapi、好的文档、好的评论