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

... hence your CB comment - with which I wholeheartedly agree :D

I've seen code such as your 2nd example fail if there's no __DATA__ section in the file.

As to the 1st example, well that's a different kettle of fish...

Given a simple script (tst.pl):

>cat tst.pl use warnings; use strict; use Fcntl qw/:flock/; open SELF, "< $0" or die ; flock SELF, LOCK_EX | LOCK_NB or die "$!";
A simple run results in...
>perl tst.pl A file descriptor does not refer to an open file. at tst.pl line 7.
Re-ruuning and generating a truss log, using >truss -f perl tst.pl  > log 2>&1, the (business) end of which is...
. . . 389372: open("tst.pl", O_RDONLY|O_LARGEFILE) = 3 389372: kioctl(3, 22528, 0x00000000, 0x00000000) Err#25 ENOTTY 389372: fstatx(3, 0x30020848, 128, 010) = 0 389372: kfcntl(3, F_SETFD, 0x00000001) = 0 389372: kfcntl(3, F_SETLK, 0x2FF222A0) Err#9 EBADF 389372: access("/usr/lib/nls/msg/en_GB/libc.cat", 0) Err#2 ENOENT 389372: access("/usr/lib/nls/msg/en_US/libc.cat", 0) = 0 389372: _getpid() = 389372 389372: open("/usr/lib/nls/msg/en_US/libc.cat", O_RDONLY) = 4 389372: kioctl(4, 22528, 0x00000000, 0x00000000) Err#25 ENOTTY 389372: kfcntl(4, F_SETFD, 0x00000001) = 0 389372: kioctl(4, 22528, 0x00000000, 0x00000000) Err#25 ENOTTY 389372: kread(4, "\0\001 &#65533;\007\007 I S O 8".., 4096) = 4096 389372: lseek(4, 0, 1) = 4096 389372: lseek(4, 0, 1) = 4096 389372: lseek(4, 0, 1) = 4096 389372: _getpid() = 389372 389372: lseek(4, 0, 1) = 4096 389372: close(4) = 0 A file descriptor does not refer to an open file. at tst.pl line 7. 389372: kwrite(2, " A f i l e d e s c r".., 68) = 68 389372: kfcntl(2, F_GETFL, 0x00000008) = 1 389372: kfcntl(1, F_GETFL, 0x00000008) = 1 389372: kfcntl(2, F_GETFL, 0x00000008) = 1 389372: close(3) = 0 389372: kfcntl(2, F_GETFL, 0x00000008) = 1
We see, from 389372: open("tst.pl", O_RDONLY|O_LARGEFILE)        = 3 that the script is successfully opened on file descriptor 3.

Later, we see that the file on descriptor 3 is both open, the operations are valid and the file will/should close across an exec call...

389372: fstatx(3, 0x30020848, 128, 010) = 0 389372: kfcntl(3, F_SETFD, 0x00000001) = 0
From 389372: kfcntl(3, F_SETLK, 0x2FF222A0)          Err#9  EBADF, we can see that the kernel considers FD3 to refer to a closed file - but we haven't seen a close - either explicitly (via a call to close()) or implicitly (via an intervening call to exec()).

Thus we can only conclude that there is an underlying problem with AIX.

As to a suitable answer ... I'm afraid I can't help you (aside from the fact that there is, in perl 5.8, nothing untoward mentioned in perlaix - but I expect you already know that! :-) :-((

A user level that continues to overstate my experience :-))

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:31 UTC
    Bloodnok,
    Thanks! Would you be able to try the same code using File::FcntLock as suggested by tye? I don't have an environment where I can play as this is really coming from another group (I work mostly on Solaris boxes). At least knowing if that will work or if this is strictly an AIX issue will go along way to saving time.

    Again, thanks for confirming this is an issue on AIX.

    Cheers - L~R

      As the trace shows, flock is implemented via fcntl on AIX ... so there shouldn't be any difference.

      The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
      No probs LR - at least _you_ have a decent box/OS on which to work :D.

      I hope that there's no rush for the test - I'm not sure I'll have the time 'til Tuesday (Monday being a bank holiday in the UK an' all).

      Will keep you posted...

      A user level that continues to overstate my experience :-))