sridhar pothuganti
sridhar pothuganti

Reputation: 19

Flock command in AIX

when I was trying to use flock in AIX box I was getting flock not found. System admin has installed util-linux package but he said flock executable is not available in AIX. Please let me know how to get flock command in AIX??

Upvotes: 2

Views: 999

Answers (2)

Lorinczy Zsigmond
Lorinczy Zsigmond

Reputation: 1910

You can compile flock.c from package util-linux, but it won't have the whole functionality of the linux version:

  1. flock -n <handle> doesn't work, because on AIX, child and parent processes don't share file-locks.

  2. With option -w <timeout> it will wait forever (if timeout is non-zero), as flock(2) on AIX doesn't return with errno=EINTR when a timer fires (SIGALRM).

Here's an example that does work on AIX:

#!/bin/sh

if [ "x$1" = x-locked ]; then
    shift
else
    echo "Trying flock on 'flock.tmp'"
    if ! flock --verbose -w 0 flock.tmp "$0" -locked "$@"; then 
        echo 'Flock failed'
    fi
    exit
fi

echo "After flock -- sleeping 15 sec"
sleep 15
echo "Exiting"

Here is the flock version I compiled from source: http://web.axelero.hu/lzsiga/flock.tgz

Upvotes: 2

pedz
pedz

Reputation: 2349

This package I think has the flock command. http://www.perzl.org/aix/index.php?n=Main.Util-linux

Upvotes: -2

Related Questions