How can I check if a file is being used by another application?

I need to process the video file, and I need the file to be full before opening it. Therefore, I need to check whether the file is open or not, before processing it, but it is opened by another process. Any idea how to check this? I am using Linux.

+3
source share
1 answer

Without any additional gems, there can be a somewhat wasteful way:

if %x[lsof -F n].split("\n").grep(/yourfilename/).empty? # all clear else end 

Or

 if system %Q[lsof #{filename}] # still open.. else # all clear end 

Or ignore my hacked sentence and use the stone for this: https://github.com/jordansissel/fosl

+6
source

All Articles