flock(): removing locked file without race condition?
Sorry if I reply to a dead question: After locking the file, open another copy of it, fstat both copies and check the inode number, like this: lockfile = “/tmp/some_name.lock”; while(1) { fd = open(lockfile, O_CREAT); flock(fd, LOCK_EX); fstat(fd, &st0); stat(lockfile, &st1); if(st0.st_ino == st1.st_ino) break; close(fd); } do_something(); unlink(lockfile); flock(fd, LOCK_UN); This prevents the … Read more