如何找到的文件句柄,我的进程已经在Linux中打开? [英] How do I find the file handles that my process has opened in Linux?

查看:301
本文介绍了如何找到的文件句柄,我的进程已经在Linux中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们执行Unix的一个分支,打开的文件句柄是继承的,如果我们不需要使用它们,我们应该将其关闭。然而,当我们使用库文件句柄可被打开一个我们没有访问到手柄。我们如何检查这些打开的文件句柄?

When we perform a fork in Unix, open file handles are inherited, and if we don't need to use them we should close them. However, when we use libraries, file handles may be opened for which we do not have access to the handle. How do we check for these open file handles?

推荐答案

如果库正在打开,你不知道的文件,你怎么知道他们并不需要他们后叉?未导出手柄内部库的细节,如果库希望他们关闭它会注册一个atfork()处理程序来关闭它们。走在后面的一些片code关闭其文件的背后处理会导致细微的难以调试的问题,因为当它试图与它知道它正确打开的句柄到工作库将意外错误,但没有关闭。

If the libraries are opening files you don't know about, how do you know they don't need them after a fork? Unexported handles are an internal library detail, if the library wants them closed it will register an atfork() handler to close them. Walking around behind some piece of code closing its file handles behind its back will lead to subtle hard to debug problems since the library will error unexpectedly when it attempts to work with a handle it knows it opened correctly, but did not close.

这篇关于如何找到的文件句柄,我的进程已经在Linux中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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