设为首页 加入收藏

TOP

fcntl函数加文件锁(二)
2015-07-16 12:57:43 来源: 作者: 【 】 浏览:84
Tags:fcntl 函数 文件
bling the set-group-ID permission bit (see? chmod(1) and chmod(2)).


这是说,要实现强制性锁则须将文件所在的文件系统用"-o mand"参数来挂载,并且使用chmod函数将文件用户组的x权限去掉。然后用上面同样的代码就可以了。我第一次见这么奇特的函数,实现一个功能并不是通过本身的参数控制,而是系统设置.....幸好我也不用强制性锁。


  以上是fcntl加文件锁的简单例子。需要注意的是不同系统的实现并不一样,宏定义也不一样。如:


http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/fcntl.h


?/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
#define? ? F_RDLCK? ? ? ? 1? ? ? ? /* shared or read lock */
#define? ? F_UNLCK? ? ? ? 2? ? ? ? /* unlock */
#define? ? F_WRLCK? ? ? ? 3? ? ? ? /* exclusive or write lock */


而在debian中,/usr/include/bits/fcntl.h
/* For posix fcntl() and `l_type' field of a `struct flock' for lockf().? */
#define F_RDLCK? ? ? ? 0? ? ? /* Read lock.? */
#define F_WRLCK? ? ? ? 1? ? ? /* Write lock.? */
#define F_UNLCK? ? ? ? 2? ? ? /* Remove lock.? */


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++中的重载、覆盖、隐藏 下一篇Linux使用共享内存通信的进程同步..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: