有一个进程A,当A出错时,弹出系统错误对话框(例如内存报错的"指定内存不能为读")。
现在我想在另外一个进程B中知道A弹出系统错误的,这样我能够实现重启A,请问怎么实现?
求教高手。

解决方案 »

  1.   

    B作为父进程启动A创建子进程A的时候使用 DEBUG_PROCESS 标志,这样,A中出现系统错误对话框(例如内存报错的"指定内存不能为读")时B应该就能收到消息.see
    MSDN
    CreateProcess dwCreationFlags ,
    Process Creation Flags
    DEBUG_PROCESS:
    The calling thread starts and debugs the new process and all any child processes of the new process that are created with DEBUG_PROCESS. It can receive all related debug events using the WaitForDebugEvent function. 
    If this flag is combined with DEBUG_ONLY_THIS_PROCESS, the caller debugs only the new process.Windows Me/98/95:  This flag is not valid if the new process is a 16-bit application.
      

  2.   

    这种可以B周期性的发送消息给A,A返回一些信息,类似心跳包的原理,当达到一定时间,A没有返回信息给B,那么就认为A出错了,这时B把A TerminateProcess结束掉,然后CreateProcess重启A
      

  3.   

    如果 A B 都是自己的程序,可以像 ls 用消息的机制,定时取回应值。
    如果不是,可以考虑用钩子,写个 dll 注入到远程进程,注入时给那个程序添加一个自定义的 SEH 处理函数。