Chinaunix首页 | 论坛 | 博客
  • 博客访问: 27920
  • 博文数量: 7
  • 博客积分: 420
  • 博客等级: 下士
  • 技术积分: 105
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-29 11:11
文章分类
文章存档

2008年(7)

我的朋友
最近访客

分类:

2008-05-03 15:34:20

#include
#include
#include
 
static struct flock lock_it, unlock_it;
static int lock_fd = -1;
 
void lock_init(void)
{
 char lock_file[] = "/tmp/cheney.servers.lock.XXXXXX";
 lock_fd = mkstemp(lock_file);
 unlink(lock_file);
 lock_it.l_type = F_WRLCK;
 lock_it.l_whence = SEEK_SET;
 lock_it.l_start = 0;
 lock_it.l_len = 0;
 unlock_it.l_type = F_UNLCK;
 unlock_it.l_whence = SEEK_SET;
 unlock_it.l_start = 0;
 unlock_it.l_len = 0;
}
 
void lock_wait(void)
{
 int rc;
 while ((rc = fcntl(lock_fd, F_SETLKW, &lock_it)) < 0) {
  if (errno == EINTR)
   continue;
  else
   return;
 }
}
 
void lock_release(void)
{
 if (fcntl(lock_fd, F_SETLKW, &unlock_it) < 0)
  return;
}
阅读(499) | 评论(0) | 转发(0) |
0

上一篇:rpm命令使用

下一篇:linux系统调用列表

给主人留下些什么吧!~~