c - 在运行 Ubuntu 19.10 的 x64 系统中,文件描述符的大小(以位为单位)是多少?

标签 c linux assembly x86-64 file-descriptor

标准输入和标准输出等文件描述符的比特大小是多少,是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_tint8_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 the FILE objects associated, respectively, with the standard error, input, and output streams.

关于c - 在运行 Ubuntu 19.10 的 x64 系统中,文件描述符的大小(以位为单位)是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60477930/

相关文章:

android - 为 armv7 构建 tcc 并在 android 设备上运行它,我应该把头文件放在哪里?

C HTTP 服务器和 OpenSSL - 适用于 HTTP - 使用 HTTPS 丢弃多个/快速/并发连接

c - 为什么我的小程序崩溃了?

linux - 如何使用此脚本的旧版本更新 bash 脚本?

assembly - 英特尔架构和 IEEE 754 合规性(minNum 和 maxNum)?

宏的名称可以用作常规宏和字符串吗

linux - 为什么在许多情况下声称的实际时钟/秒大于 1,000,000?

linux - 如何理解 "A formal kernel memory-ordering model"中的试金石 #5?

c - 将 4 位数字从汇编发送到 C,以在 LCD 上显示为 ASCII 字符

c++ - 生成的代码与扩展 ASM 的预期不匹配