file test for file being open by another process?
Randal L. Schwartz
merlyn at stonehenge.com
Wed Jun 12 17:55:16 CDT 2002
>>>>> "mikeraz" == mikeraz <mikeraz at patch.com> writes:
mikeraz> I'd like to know if another process has a file open on a system.
There's no core (POSIX?) Unix API to know that. You can crawl through
kernel data structures, ala "ofiles" or "lsof" to figure it out, but
that's non-portable. Even if the file was open, you could rename it
somewhere else, and it'd still keep writing to the new place. Or
delete it, and it becomes a nameless file, that is still open.
mikeraz> The file in question is being copied from one system on a network
mikeraz> to another (read: Windows users are copying files from their local
mikeraz> drive to the Samba share point on my Linux server.)
mikeraz> When it fully arrives on the second system my process should begin
mikeraz> to work on it.
Your two choices are cooperatively, or ad-hoc.
have your client write the file into FOO.tmp, then rename when done
to FOO.done. You don't touch the FOO.tmp files.
wait until -A $file > 0.1
Sorry, that's all you get.
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
More information about the Pdx-pm-list