0
我試圖識別鎖定文本文件的進程。鎖定文件的過程
我想用碳或可可做這個。
我是新來的MacAPI,我來自WinAPI。
由於
編輯:加入的CoreFoundation標籤作爲我聽到碳是通過運行命令lsof
例如棄用
我試圖識別鎖定文本文件的進程。鎖定文件的過程
我想用碳或可可做這個。
我是新來的MacAPI,我來自WinAPI。
由於
編輯:加入的CoreFoundation標籤作爲我聽到碳是通過運行命令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.
這將列出可能已鎖定該文件的所有進程的手冊頁,但它會說哪一個真正有鎖? – Barmar 2014-08-28 23:43:46
檢查聯機幫助頁。它提到了鎖定。我將它添加到答案 – 2014-08-28 23:46:02
感謝您的澄清。儘管OP似乎在尋找API解決方案,而不是CLI。我意識到他可以使用'popen()'來運行'lsof',但他必須解析輸出。 – Barmar 2014-08-28 23:48:30