Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fcntl()作用域可见性行为?_C_Linux_Unix_Gcc_Posix - Fatal编程技术网

fcntl()作用域可见性行为?

fcntl()作用域可见性行为?,c,linux,unix,gcc,posix,C,Linux,Unix,Gcc,Posix,除了main(),是否可以在函数内部使用fcntl()?调用该文件后,该文件是否被解锁?我这样说是因为在本例中,当函数返回时,fcntl()和lockfile()中的大多数其他内容都超出了范围 int锁文件(无效){ int-fd; const char*path=“锁定文件的路径”; struct-flock-fl; fl.l_类型=F_WRLCK; fl.l_whence=寻道集; fl.l_开始=0; fl.l_len=0 fl.l_pid=getpid(); fd=开放(路径,O|RDW

除了
main()
,是否可以在函数内部使用
fcntl()
?调用该文件后,该文件是否被解锁?我这样说是因为在本例中,当函数
返回时,
fcntl()
lockfile()中的大多数其他内容都超出了范围

int锁文件(无效){
int-fd;
const char*path=“锁定文件的路径”;
struct-flock-fl;
fl.l_类型=F_WRLCK;
fl.l_whence=寻道集;
fl.l_开始=0;
fl.l_len=0
fl.l_pid=getpid();
fd=开放(路径,O|RDWR | O|CREAT);
fcntl(fd、F_设置和fl);
返回fd;
}

调用
fcntl
会锁定文件。它将一直保留,直到文件关闭或解除锁定。这些结构只需要告诉
fcntl
该做什么。

读了这篇文章,我们想讨论一下鸟类的群集行为。