锁定文件的进程

时间:2014-08-28 23:31:31

标签: macos cocoa macos-carbon core-foundation

我试图找出锁定了文本文件的进程。

我希望用Carbon或Cocoa来做这件事。

我是MacAPI的新手,我来自WinAPI。

由于

编辑:添加了corefoundation标签,因为我听说碳已被弃用

1 个答案:

答案 0 :(得分:1)

您可以通过运行命令lsof例如

来检查哪个进程正在使用文件
lsof | grep file.txt

来自lsof

的联机帮助页
The  mode character is followed by one of these lock characters, describing the type of lock applied to the
              file:

                   N for a Solaris NFS lock of unknown type;
                   r for read lock on part of the file;
                   R for a read lock on the entire file;
                   w for a write lock on part of the file;
                   W for a write lock on the entire file;
                   u for a read and write lock of any length;
                   U for a lock of unknown type;
                   x for an SCO OpenServer Xenix lock on part      of the file;
                   X for an SCO OpenServer Xenix lock on the      entire file;
                   space if there is no lock.

              See the LOCKS section for more information on the lock information character.