in reply to mkfifo/mknode

I use flock for this type of locking and it always worked like a dream for me.

Update: What I meant to say is that I use flock on the file itself to be locked, not on a separate lock file - it doesn't quite work like that.

I have done what you are doing on occasion, but in that case I opened the lock file '+<', did the flock and then a seek 0 and (over-) wrote the pid for testing, though I left that in there for support purposes.

-M

Free your mind

Replies are listed 'Best First'.
Re^2: mkfifo/mknode
by azaria (Beadle) on Jun 14, 2006 at 13:08 UTC
    Hello Moron, I tried to use the flock function but i got the error - Usage: Fcntl::constant(name, arg) at Fcntl.pm line 225. Do you have any simple example ? Thanks
      Here is a simple example of using a dedicated lock file
      my $LOCK_EX = 2; # exclusive lock on file my $LOCK_UN = 8; # unlock file my $lock_file = $ENV{ XYZ_DIR } . "/$0.lock"; open my $lh, ">$lock_file" || die "Can't open lock file $lock_file: $! +"; flock $lh, $LOCK_EX; # will wait for exclusive lock # on lock file # do the exclusive actions flock $lh, $LOCK_UN; close $lh;

      -M

      Free your mind