Happy-the-monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear brethren in Perl,

What would a perl hacker do to determine if a file is currently being written to?

I am looking for guidance on behalf of a collegue. He needs help debugging a beta release of an FTP server on a whacky unix machine. For some reason yet unknown to us, the Unix (Solaris 9) isn't allowing the FTP server to run the fuser() command on its own files - alas, we aren't system administrators there. (The FTP daemon is running as a non-privileged user)
fuser() is what different instances of the FTP daemon would do to determine, if a file was eligible to be moved, overwritten etc.

The lsof() command would also have been nice, yet it isn't installed on that machine.
flock would have been very nice, but it must run on a shared file system.

And that's all I've come up with at the moment. Got any more ideas to share?

Cheers, Sören

2004-10-22 Edited by Arunbear: Changed title from 'Is anybody using that file, tell me?', as per Monastery guidelines

  • Comment on (OT) Is anybody using that file, tell me?

Replies are listed 'Best First'.
•Re: (OT) Is anybody using that file, tell me?
by merlyn (Sage) on Oct 21, 2004 at 13:03 UTC
    The reason this question comes up all the time is that there's no traditional interface in Unix to tell if someone has a file open, so every solution is ad hoc and very unix-flavor specific. So, you're not gonna find a solution that works everywhere. Generally, people have worked out alternate strategies, like write to a temp file and rename after closing.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.