in reply to error message not working

On win32, ActivePerl 5.8.4, the 2nd process dies without the error message. I changed
flock DATA, LOCK_EX | LOCK_NB or die "Already executing: $!";
to
open my $dummy, ">lock" or die $!; flock $dummy, LOCK_EX | LOCK_NB or die "Already executing: $!";
and then I did get the error message:
Already executing: Domain error at temp2.pl line 7.

Replies are listed 'Best First'.
Re^2: error message not working
by bart (Canon) on Nov 30, 2004 at 14:01 UTC
    Ah yes. On some operating systems, you can only do a LOCK_EX on a handle that's open for writing. DATA is open for reading only. I guess that is why the original fails, and your version works.

    Update: perldoc -f flock has this to say about it:

    Note that the emulation built with lockf(3) doesn't provide shared locks, and it requires that FILEHANDLE be open with write intent. These are the semantics that lockf(3) implements. Most (all?) systems implement lockf(3) in terms of fcntl(2) locking, though, so the differing semantics shouldn't bite too many people.
    That must be the case, here. "Not too many people", right.
Re^2: error message not working
by Anonymous Monk on Nov 30, 2004 at 12:18 UTC
    does this open an actual file?
    what I was trying to do was open DATA (after __END__) to ensure that the actual script wasn't already being run. I was trying to get Merlyn's snippet from the node I mentioned above to work for me, it does work apparently, but not on windows...
    Any advise appreciated
    Jonathan
      It does open an actual file. I know what you are trying to do. I'm only suggesting it as a work-around because opening DATA isn't doing the job on win32. As I showed before, using a real sentinel file does prevent additional instances of the script from running. merlyn suggested opening DATA because the code is simpler that way.