c - 文件描述符(在 C 中打开的 fd)是否与其进程 ID 相同?

标签 c linux file process

在 C 中使用 open() 函数时,我得到一个 fd(文件描述符)。我想知道它是否与其进程 ID 相同,因为据我所知,fd 是一个整数。

最佳答案

不,不是。
PID是进程标识符,文件描述符是文件处理程序标识符。

特别来自维基百科关于文件描述符的内容:

(...) file descriptor (FD) is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems.

In POSIX, a file descriptor is an integer, specifically of the C type int. (...)

对于 PID:

[PID] is a number used by most operating system kernels, — such as that of UNIX, Mac OS X or Microsoft Windows — to temporarily uniquely identify a process (...)

关于c - 文件描述符(在 C 中打开的 fd)是否与其进程 ID 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653265/

相关文章:

linux - Bash 转义字符

C++从文件中读取char,转换为long long int

java - 计算数组列中值的平均值?

c - 手动优化嵌套循环

c - 从文本文件到二维整数数组的读取和处理,中间有语句

python - 使用 Python 更改 SAMBA 上的用户密码

c - Ubuntu Linux 使用 Unix 域套接字发送文件描述符

c - 在c中将整数写入文件

无法理解三元运算符的行为

c - 个人 Valgrind 异常