简体   繁体   English

nftw文件句柄的总数或可用数量

[英]nftw total or available number of file handles

nftw wants a parameter for the number of file handles to use. nftw一个参数来表示要使用的文件句柄数。 I've seen a couple of examples specifying this as 20 (this is the POSIX guaranteed minimum? but one could also use getrlimit or sysconf to get the actual available number). 我看过几个例子,将其指定为20(这是POSIX保证的最小值?但是也可以使用getrlimitsysconf来获取实际可用的数量)。 Should this not be specified as 17 because three file handles are already used for stdin/out/err? 是不应该将其指定为17,因为stdin / out / err已经使用了三个文件句柄? Or am I misunderstanding how it works? 或者我误解了它是如何工作的? (Similarly if we get the actual available number with getrlimit or sysconf , should we subtract 3 before passing the parameter?) (同样,如果我们使用getrlimitsysconf获取实际可用的数字,我们应该在传递参数之前减去3吗?)

Leaving at least three file descriptors open for stdin, stdout, and stderr sounds like excellent advice. 至少为stdin,stdout和stderr打开三个文件描述符听起来像是一个很好的建议。 Further, you might have a descriptor or two open for your own needs. 此外,您可能会根据自己的需要打开一个或两个描述符。 A quick scan of my system shows a range between 0 and 109 open descriptors, with 4 being quite common. 快速扫描我的系统显示0109开放描述符的范围,其中4非常常见。

The number of file descriptors is the total number of file descriptors the process can have. 文件描述符的数量是进程可以拥有的文件描述符的总数。 Functions like sysconf doesn't know if some of them are already used or not. sysconf这样的函数不知道是否已经使用了其中一些函数。 You can test this by opening a number of files, and sysconf should return the same value both before and after. 您可以通过打开许多文件来测试它, sysconf应该在之前和之后返回相同的值。

It's probably a good idea to subtract 3 for the standard file descriptors, and maybe a couple of more just in case. 对标准文件描述符减去3可能是一个好主意,也许还有几个以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM