我已经实现了一个文件锁定机制,沿着
linux手册页中“open”的建议,其中指出:
Portable programs that want to perform atomic file locking using a
lockfile,and need to avoid reliance on NFS support for O_EXCL,can
create a unique file on the same file system (e.g.,incorporating
hostname and PID),and use link(2) to make a link to the lockfile. If
link(2) returns 0,the lock is successful. Otherwise,use stat(2) on
the unique file to check if its link count has increased to 2,in
which case the lock is also successful.
这似乎工作得很好,但是为了在我的测试中获得100%的代码覆盖率,我需要覆盖链接数增加到2的情况.