- 论坛徽章:
- 0
|
~请教在fnctl中的struct flock lockvar; 成功对文件加write lock ,lockvar.l_pid无效?
/*OS:fedora12 g++ (GCC) 4.4.2 20091027*/
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
int main(int argc,char *argv[])
......
struct flock lockvar;
lockvar.l_type=F_WRLCK;
lockvar.l_whence=SEEK_SET;
lockvar.l_start=0;
lockvar.l_len=0;
int fd=open(argv[1],O_RDWR);
......
if((fcntl(fd,F_SETLK,&lockvar)==0)
{
printf("pid=%d\n",lockvar.l_pid); //这句根本没有输出正确的pid?
printf("getpid=%d\n",getpid());//这句的pid是正常的,本应上下结果是一致的吧!
}
......
查看man 有这么一段话,
Several systems have more fields in struct flock such
as, for example, l_sysid. Clearly, l_pid alone is not
going to be very useful if the process holding the lock
may live on a different machine.
还是这个成员变量在fedora 下没用作用?请指教! |
|