开发者

sub-process termination in case of a hang(Win)

开发者 https://www.devze.com 2023-03-22 00:11 出处:网络
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 k

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消