Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Process 用Python编写看门狗_Process_Signals_Monitoring_Watchdog - Fatal编程技术网

Process 用Python编写看门狗

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

我需要在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_time - begin_time
    if not diff_time > sleep_time:
        sleep(sleep_time - diff_time)
由于“忙等待是不好的”,而且这会占用约10%的CPU,我想知道是否有更好的方法来解决这个问题:

  • 进行通知/事件处理,而不是轮询。 请注意,我并不是暗示进程终止时会触发任何通知/事件,而是询问操作系统是否可以确定java程序已死亡

  • 修改生成java程序的upstart脚本,以便在进程停止时重新启动它

  • 更好的解决方案? 也许类似,但对于linux进程


  • 编写bash脚本以在while循环中运行程序

    #!/bin/bash
    while true; do 
        java -jar offendingProgram.jar
    done
    
    然后将脚本从您启动它的任何地方加载。

    -Python、生成和控制进程、事件通知、xml-rpcapi、好的文档、好的评论