CreateProcess和孤立流程 [英] CreateProcess and Orphan Processes

查看:169
本文介绍了CreateProcess和孤立流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows XP系统,

我们开发了一个程序(Foobar),该程序调用CreateProcess,然后退出,从而导致一个非终止的孤立进程(Orphan).问题是,当我们尝试移动,复制,删除等Foobar或其文件夹时,Windows会显示无法删除文件,因为文件夹/程序正在被其他进程使用"消息,因为Foobar似乎仍与孤儿息息相关.

为什么会这样呢?我们调用Foobar中的CreateProcess()之后立即调用Close_Handle以释放线程并处理资源.剩下哪些依赖项或资源(如果有的话)将Foobar与孤儿联系起来?

I am using a Windows XP system,

We developed a program (Foobar) that makes a call to CreateProcess and then exits resulting in an non-terminating orphan process (Orphan). The issue is that when we attempt to move, copy, delete, etc. Foobar or its folder, Windows displays a cannot-dostuff-because-folder/program-is-being-used-by-another-process message since Foobar seems to still be tied to Orphan.

Why is this the case? We make calls to Close_Handle to release the thread and process resources immediately following CreateProcess() in Foobar. What dependencies or resources (if any exist) are left over that are tying Foobar to Orphan?

推荐答案

这是因为您的孤儿"进程仍处于打开状态,并且尚未释放您尝试访问的文件系统资源.您需要做的是更改流程对象的范围,以便在您的应用关闭时,也可以终止有问题的流程.
It''s because your "orphaned" process is still open, and hasn''t released the filesystem resources that you''re trying to access. What you need to do is change the scope of the process object so that when your app closes, the process in question can also be terminated.


我们已经找到了解决方案.孤立进程正在继承并保留其祖父母进程的资源,从而阻止了祖父母进程再次运行.

我们的主要应用程序需要此祖父母流程才能正常运行,因此只需将CreateProcess的第五个参数(bInheritHandles)设置为FALSE,以防止子流程继承父流程的句柄.一旦做到这一点,即使在运行orhpan进程的情况下,祖父母进程也能够启动并正确运行.

感谢您的帮助!
We''ve discovered the solution. The orphan process is inheriting and holding onto resources from its grandparent process, which prevents the grandparent process from running again.

Our main application needs this grandparent process in order to function correctly so all it took was to set the fifth paramter of CreateProcess (bInheritHandles) to FALSE to keep child processes from inheriting the parent process''s handles. Once we did that, the grandparent process was able to start and function correctly even with the orhpan process running.

Thanks for your help!


这篇关于CreateProcess和孤立流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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