如何确定进程是否被过早终止(例如,任务管理器->终止) [英] How to determine if a process was killed prematurely (eg. Task Manager->Terminate)

查看:98
本文介绍了如何确定进程是否被过早终止(例如,任务管理器->终止)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用服务中的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?

推荐答案

您可以使用

you can check with WaitForSingleObject and Event synchronization object.  

 

您可以查看以下内容以获取更多信息

You can check with the following for more information

http://stackoverflow.com/questions/5907917/how-to-use-win32-createprocess-function-to-wait-until-the-child-done-to-write-to


这篇关于如何确定进程是否被过早终止(例如,任务管理器->终止)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆