use Fcntl ':flock'; use POSIX ':sys_wait_h'; my $fh; open($fh, 'somefile.txt'); flock($fh, LOCK_EX); my $pid = fork(); if ($pid == 0){ #this is the child...does it have the lock? #do some stuff.... exit; } elsif (!defined($pid)) { die "Couldn't fork: $!"; } else { #this is the parent...does it have the lock? waitpid($pid, &WNOHANG); }
In reply to Fork + Flock = Who Gets the Lock? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |