c/c++,mfc:不将打开的文件/句柄传递给生成的进程
在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯 - 很抱歉在这里猜测一下,但是您确定 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