H
Hallvard B Furuseth
I need a to pass a file lock to the parent process - and
to detect that this works.
The best answer would be passing a file descriptor through a socket, but
I couldn't find how to do that with Perl.
Another way is to open() the file in the parent and flock() it in the
child - that works on my host, but I don't know how to test reliably if
it works. Perl can use either the C system call flock(), lockf() or
fcntl() for file locks, and I don't even know if it is reliable for the
flock() system call.
use Fcntl qw
flock);
open(LK, "+>/tmp/foobar.lock") or die;
unless (fork()) {
# Child
flock(LK, LOCK_EX) or die;
exit(0);
}
# Parent
wait; die if $?;
# LK is locked
to detect that this works.
The best answer would be passing a file descriptor through a socket, but
I couldn't find how to do that with Perl.
Another way is to open() the file in the parent and flock() it in the
child - that works on my host, but I don't know how to test reliably if
it works. Perl can use either the C system call flock(), lockf() or
fcntl() for file locks, and I don't even know if it is reliable for the
flock() system call.
use Fcntl qw
open(LK, "+>/tmp/foobar.lock") or die;
unless (fork()) {
# Child
flock(LK, LOCK_EX) or die;
exit(0);
}
# Parent
wait; die if $?;
# LK is locked