c/c++,mfc:不将打开的文件/句柄传递给生成的进程

发布于 2024-09-26 03:27:08 字数 388 浏览 0 评论 0原文

在unix中,我知道例程:在子进程中的fork()和exec()之间,我关闭除stdin/out/err之外的所有内容,以便所有打开的端口或文件都不会传递给我想要运行的程序。

但我该如何在 Windows 中执行此操作呢?就我而言,我正在用 C/C++ 实现 DLL,并且我需要关闭我打开的一些文件(通过某些对象间接打开)以及加载 dll 的应用程序打开的套接字,以便这些打开的文件句柄不被打开。传递给我正在生成的应用程序。应用程序不会将这些句柄传递给 DLL,因为我的代码不需要这些...

到目前为止,代码只是调用 _spawnl(_P_NOWAIT, "foo.exe", "foo.exe", "arg1", " arg2",NULL); Visual Studio 2008(如果有的话)。

感谢您的帮助。

In unix I know the routine: between fork() and exec() in the child I close everything except stdin/out/err, so that all the open ports or files are not passed to the program I want to run.

But how do I do this in windows? In my case I'm implementing a DLL in C/C++, and I need to close both some files I opened (indirectly via some objects) and the sockets opened by the Application that loaded the dll, so that these open file handles are not passed to the application I'm spawning. The app doesn't pass those handles to the DLL, as my code shouldn't need those...

So far the code simply calles _spawnl(_P_NOWAIT, "foo.exe", "foo.exe", "arg1", "arg2",NULL);
Visual Studio 2008 if that matters.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2024-10-03 03:27:08

嗯 - 很抱歉在这里猜测一下,但是您确定 Windows 中的 spawnl 会传递打开的文件句柄吗?

如果是这样,也许您想查看 CreateProcess 和 StartupInfo - 这些可以更好地控制传递/继承到新进程的内容

hmm - sorry to be guessing here a little, but are you sure spawnl in Windows passes the open file handles?

If so, maybe you want to look at CreateProcess, and StartupInfo - these allow finer control over what gets passed/inherited to the new process

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文