标签:
bool checkOnly() { const char filename[] = "./lockfile"; int fd = open (filename, O_WRONLY | O_CREAT , 0644); int flock = lockf(fd, F_TLOCK, 0 ); if (fd == -1) { return false; } //给文件加锁 if (flock == -1) { return false; } //程序退出后,文件自动解锁 return true; }
标签:
原文地址:http://www.cnblogs.com/qk2015/p/4734584.html