How do you check if a file is open using Perl?

file, perl

Solution

POSIX does not provide any way to do this. Therefore, no portable solution is possible given the current portable O/S interface available.

You’d have to craft some higher level approach that provides a single point of access for the opening bits. It’s like with lock files.

Problem

Given the name of a file, how can I determine if the file is currently opened or in-use? (I am talking about files rather than Perl file handles.) Please note that I am looking for a general-purpose Perl solution rather than an operating system-specific one. At a minimum, I would like something that works both on Windows and GNU/Linux-based systems.

Original source

Related problems