我正在使用服务中的CreateProcess()启动子进程(我没有源代码控制权的第三方应用程序),并使用GetExitCodeProcess()检查其退出代码以确定是否成功(0)或失败(1). 如果某人过早地终止了该进程(例如通过TaskManager),则我需要父级将此情况检测为一种特殊情况,并与正常的成功/失败过程完成不同地进行处理. 在我的测试中,终止过程例如任务管理器会导致进程以(1)退出,因此我无法区分进程以失败代码完成还是进程过早终止之间的区别. 我惊讶地发现Win32 API似乎没有确定孩子是否被过早杀死的功能(我在寻找类似于GetExitCodeProcess的东西).
I'm using CreateProcess() from a service to start a child process (3rd party applications for which I don't have source code control over) and am checking its exit code with GetExitCodeProcess() to determine success (0) or failure (1). If someone kills the process prematurely (eg. via TaskManager) I need the parent to detect this as a special condition and handle it differently from a normal success/fail process completion. In my tests, terminating the process from eg. the Task Manager causes the process to exit with (1), so I can't tell the difference between the process completing with a fail code, or if it was terminated prematurely. I was surprised to find the Win32 API doesn't seem to have a function to determine if the child was killed prematurely (I was looking for something similar to GetExitCodeProcess).
调用CreateProcess()的程序是否可以检测子进程是否提前终止?
Is there a way for the program that invoked CreateProcess() to detect if the child process was terminated prematurely?
推荐答案
您可以使用 WaitForSingleObject 和 事件 同步对象.
you can check with WaitForSingleObject and Event synchronization object.
您可以查看以下内容以获取更多信息
You can check with the following for more information
stackoverflow/questions/5907917/how-to-use-win32-createprocess-function-to-wait-until-the-child-done-to-write-to
更多推荐
如何确定进程是否被过早终止(例如,任务管理器
发布评论