如何确定进程是否被过早终止(例如,任务管理器

编程入门 行业动态 更新时间:2024-10-20 15:48:13
本文介绍了如何确定进程是否被过早终止(例如,任务管理器->终止)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

如何确定进程是否被过早终止(例如,任务管理器

本文发布于:2023-11-27 08:26:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:任务管理器   进程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!