标准输入和标准输出等文件描述符的比特大小是多少,是32位整数吗?
最佳答案
如果您谈论的是 Linux 系统调用返回(并用于)的实际文件描述符,请查看 open
的联机帮助页正如@JonathanLeffler 建议的那样。
例如:
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. [...] The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process.
鉴于类 Unix 系统是 LP64,int
因此文件描述符是 32 位宽。
但是,请注意,内核会为您提供尽可能小的整数并且您通常会在此之前达到限制(请参阅Limits on the number of file descriptors),这可能是由于内核全局限制或软/硬限制。
这意味着,如果您真的需要它,理论上您可以使用较小的整数来存储您的文件描述符,例如一个int16_t
或 int8_t
(假设您的进程一次不使用那么多文件描述符)。
相反,如果您指的是 stdin
等等,它们不是文件描述符,而是 C 标准定义的文件流。
它们是扩展为具有指针类型 ( FILE *
) 的表达式的宏,典型的 64 位平台(如 x86_64)中的指针是 64 位宽的。
参见 7.21p3(输入/输出 <stdio.h>
):
stdin stdout stderr
which are expressions of type ‘‘pointer to
FILE
’’ that point to theFILE
objects associated, respectively, with the standard error, input, and output streams.
关于c - 在运行 Ubuntu 19.10 的 x64 系统中,文件描述符的大小(以位为单位)是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60477930/