简体   繁体   English

在运行 Ubuntu 19.10 的 x64 系统中,文件描述符的大小是多少?

[英]What is the size in bits of a file descriptor in an x64 system running Ubuntu 19.10?

文件描述符(例如标准输入和标准输出)的位大小是多少,它是 32 位整数吗?

If you are talking about the actual file descriptors returned by (and used for) Linux syscalls, then take a look at the manpage for open etc. as @JonathanLeffler suggests.如果您正在谈论由(并用于)Linux 系统调用返回的实际文件描述符,那么请查看open等的联机帮助页。@JonathanLeffler 建议。

For instance:例如:

 int open(const char *pathname, int flags);

The return value of open() is a file descriptor, a small, nonnegative integer that is used in subsequent system calls. open()的返回值是一个文件描述符,一个小的非负整数,用于后续系统调用。 [...] The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process. [...] 成功调用返回的文件描述符将是该进程当前未打开的最小编号的文件描述符。

Given that Unix-like systems are LP64, int and therefore the file descriptors are 32-bit wide.鉴于类 Unix 系统是 LP64、 int ,因此文件描述符是 32 位宽。

However, note that the kernel will give you as small integers as possible and that you will typically reach a limit way before that (see Limits on the number of file descriptors ) either due to the kernel global limit or the soft/hard limits.但是,请注意,内核会为您提供尽可能小的整数,并且由于内核全局限制或软/硬限制,您通常会在此之前达到限制方式(请参阅文件描述符数量的限制)。

This means that, if you really needed it, you could in theory use a smaller integer to store your file descriptors, eg an int16_t or an int8_t (assuming that your process does not use that many file descriptors at a time).这意味着,如果您真的需要它,理论上您可以使用较小的整数来存储文件描述符,例如int16_tint8_t (假设您的进程一次不使用那么多文件描述符)。


If, instead, you are referring to stdin etc., those are not file descriptors but file streams defined by the C standard.相反,如果您指的是stdin等,则它们不是文件描述符,而是由 C 标准定义的文件流。

They are macros which expand to expressions with pointer type ( FILE * ), and pointers in a typical 64-bit platform like x86_64 are 64-bit wide.它们是扩展为具有指针类型 ( FILE * ) 的表达式的宏,并且在典型的 64 位平台(如 x86_64)中的指针是 64 位宽的。

See 7.21p3 (Input/output <stdio.h> ):参见 7.21p3(输入/输出<stdio.h> ):

 stdin stdout stderr

which are expressions of type ''pointer to FILE '' that point to the FILE objects associated, respectively, with the standard error, input, and output streams.它们是“指向FILE的指针”类型的表达式,它们指向分别与标准错误、输入和输出流相关联的FILE对象。

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

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