in reply to Lightweight Solution To "Only 1 Process Running" On AIX

The error in both cases is "unable to lock: A file descriptor does not refer to an open file."

Considering your code does a plain exit if the flock fails, I quite surprised you get any error message at all.

Perhaps the code you are showing isn't the code you are running?

  • Comment on Re: Lightweight Solution To "Only 1 Process Running" On AIX

Replies are listed 'Best First'.
Re^2: Lightweight Solution To "Only 1 Process Running" On AIX
by Limbic~Region (Chancellor) on May 01, 2009 at 15:17 UTC
    JavaFan,
    The code shown is the extract from the slides presented by Dominus. I provided it here so people wouldn't have to go to an offsite location to see them. Here is complete running code that demonstrates the problem:
    #!/usr/bin/perl use strict; use warnings; use Fcntl qw/:DEFAULT :flock/; open(SELF, '<', $0) or die "Unable to open '$0' for reading: $!"; flock SELF, LOCK_EX | LOCK_NB or exit; print "I must be the only process running\n"; sleep 300;
    and
    #!/usr/bin/perl use strict; use warnings; use Fcntl qw/:DEFAULT :flock/; flock DATA, LOCK_EX | LOCK_NB or exit; print "I must be the only process running\n"; sleep 300; __DATA__

    Cheers - L~R