执行等效的“杀死进程树”在Windows上的c ++ [英] Performing equivalent of "Kill Process Tree" in c++ on windows

查看:224
本文介绍了执行等效的“杀死进程树”在Windows上的c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个c ++任务,将分叉一个新的进程。该过程可能有几个子进程。如果任务运行超过一个分配的时间,我们将要杀死那个分叉的进程。但是,我们不想孤立它产生的进程。我们希望他们都死。我使用Process Explorer,它有一个杀死进程树选项,类似于Windows任务管理器的结束进程树,所以我猜/假设有一个公共API来做到这一点。有没有人这样做,或者知道对公共API的引用?

We have a c++ task that will fork a new process. That process in turn may have several child processes. If the task runs past an allotted time, we will want to kill that forked process. However, we don't want to orphan the processes it has spawned. We want them all to die. I have used Process Explorer and it has a "Kill Process Tree" option, similar to Windows Task Manager's "End Process Tree", so I'm guessing/assuming there is a public API to do this. Has anyone done this, or know of a reference to a public API that does?

Thx,
Brett

Thx, Brett

推荐答案

您可能需要考虑Jobs API。 CreateJobObject 和朋友。您可以通过设置适当的属性来强制子进程停留在作业中。然后你可以随时调用TerminateJobObject。

You might want to consider the "Jobs API". CreateJobObject and friends. You can enforce children processes to stay within the Job, by setting appropriate attribute. Then you can call TerminateJobObject whenever you want.

澄清:这不是任务管理器。

Clarification: this is NOT what Task Manager does.

这篇关于执行等效的“杀死进程树”在Windows上的c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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