.NET 中的进程管理 [英] Process management in .NET

查看:57
本文介绍了.NET 中的进程管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个用 C++ 编写的辅助进程,我打开它,给它提供参数,然后它通过标准输出流将信息反馈给我的程序.

So i have a helper process written in C++ and I open it, feed it arguments, and it feeds my program back information through the standardoutput stream.

附注.我没有帮助进程 exe 的源代码.

PS. I don't have the source for the helper process exe.

如果我的应用程序被任务管理器终止,或者由于某种原因崩溃,我如何确保我的助手 exe 已关闭?这可能吗?我需要外部文件吗?

If my application were to be terminated from the task manager, or for some reason crash, how could I ensure that my helper exe is closed? Is this possible? Would I need an external file?

推荐答案

使用 用于管理进程组的作业对象.在这种情况下,您想使用 CreateJobObject 创建作业对象,请使用SetInformationJobObject 设置 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 标志,并将辅助进程分配给使用 AssignProcessToJobObject 的作业.除非您想终止辅助进程,否则不要关闭作业对象的句柄.当您的进程终止(通过任何方式)时,句柄将关闭,您的辅助进程将被终止.

Use Job Objects to manage groups of processes. In this case you want to create a job object using CreateJobObject, use SetInformationJobObject to set the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag, and assign the helper process to the job using AssignProcessToJobObject. Don't close the handle to the job object unless you want to kill the helper process. When your process terminates (through any means), the handle will be closed and your helper process will be killed.

这篇关于.NET 中的进程管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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