如何检查其他应用程序是否正在使用文件? [英] How can I check if a file is being used by other application?
本文介绍了如何检查其他应用程序是否正在使用文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要处理视频文件,并且需要在打开文件之前完成该文件.因此,在处理文件之前,我需要检查文件是否已打开,但已由另一个进程打开.知道如何检查吗?我正在使用Linux.
I need to process a video file, and I need the file to be completed before I open it. So I need to check if the file is opened or not before processing it, but opened by another process. Any idea how to check this? I'm using Linux.
推荐答案
在没有任何其他宝石的情况下,一种稍微浪费的方法可能是:
Without any additional gems, a slightly wasteful way might be:
if %x[lsof -F n].split("\n").grep(/yourfilename/).empty?
# all clear
else
end
或
if system %Q[lsof #{filename}]
# still open..
else
# all clear
end
或者,忽略我被黑的建议,并为此使用一个宝石: https://github.com/jordansissel/fosl
Or, ignore my hacked suggestion and use a gem for this: https://github.com/jordansissel/fosl
这篇关于如何检查其他应用程序是否正在使用文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文