c++ - fcntl() 中的第三个参数是什么

标签 c++ c

我不确定 fcntl() 中的第三个参数,我确实知道当第二个arg改变时它是不同的,当第二个arg是F_GETLK时它是一个指针但是当第二个参数是 F_GETFL 时等等,第三个参数应该是什么?

从 APUE 中,当第二个参数为 F_GETFL 时,它为 0

无论如何,谢谢:)

最佳答案

fcntl() can take an optional third argument. Whether or not this argument is required is determined by cmd. The required argument type is indicated in parentheses after each cmd name (in most cases, the required type is int, and we identify the argument using the name arg), or void is specified if the argument is not required.

F_SETLK, F_SETLKW, and F_GETLK are used to acquire, release, and test for the existence of record locks (also known as byte-range, file- segment, or file-region locks). The third argument, lock, is a pointer to a structure that has at least the following fields (in unspecified order).

As with traditional advisory locks, the third argument to fcntl(), lock, is a pointer to an flock structure. By contrast with traditional record locks, the l_pid field of that structure must be set to zero when using the commands described below.

此链接将帮助您解决问题 http://man7.org/linux/man-pages/man2/fcntl.2.html

关于c++ - fcntl() 中的第三个参数是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625339/

相关文章:

c - 当不在 main 内部工作时

c++ - 用于跨线程分配和免费的良好分配器

c - 重心坐标。 C 中点相对于凹多边形的谐波扭曲

c++ - 为什么C/C++中没有||=运算符?

c++ - OpenCV:使用函数 cvGoodFeaturesToTrack 时出错

c - 从二进制文件读取和写入 malloc 链表

c - 库中未实现函数的 Makefile

c++ - 使用迭代器连接 vector 中的元素

c++ - g++ 编译器中带有引用参数的构造函数

c++ - 为什么此代码返回段错误错误?