挂起时子进程终止(Win)
我有一个名为“代理”的进程,它生成一个名为“连接”的新进程。这个“连接”进程加载服务 dll。 “Connect”进程启动一个子进程(cmd.exe),我想知道是否由于某些原因加载的dll导致挂起或崩溃,如何确保“cmd.exe”终止。
I have a Process called "Agent" it spawns a new process called "Connect". This "Connect" process loads the service dll's. The "Connect" process start a sub process(cmd.exe), I would like to know if for some reasons the loaded dll's cause a hang or a crash, how to ensure that "cmd.exe" is terminated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 CreateProcess 生成新进程。这涉及到设置并传入一个 PROCESS_INFORMATION 结构:如果对 CreateProcess 的调用有效,它将包含新进程 (hProcess) 的句柄。
您现在可以对此进程句柄执行 WaitForSingleObject 以查看进程何时完成。如果对象没有触发(即进程没有终止),WaitForSingleObject 允许您超时,从而采取行动(我认为是 TerminateProcess)。
Use CreateProcess to spawn the new process. The involves setting up and passing in a PROCESS_INFORMATION structure: which will contain a handle to the new process (hProcess) if the call to CreateProcess works.
You can now do a WaitForSingleObject on this process handle to see when the process finishes. WaitForSingleObject allows you to timeout if the object does not trigger (i.e. process does not terminate), and hence take action (TerminateProcess I presume).