lockfd, unlockfd, lockfdpid, lockdev, unlockdev, lockdevpid - Locking functions

SYNOPSIS

int lockfd(fd, shared, wait)
int fd;
int shared;
int wait;

int unlockfd(fd)
int fd;

int lockfdpid(fd, shared)
int fd;
int shared;

int lockdev(gename, wait)
char *gename;
int wait;

int unlockdev(key)
int key;

int lockdevpid(gename)
char *gename;

DESCRIPTION

These routines are used for locking and unlocking open files and named devices. Locking is based on the UNIX flock intrinsic, and is advisory only. Non-cooperating applications can circumvent locks. One advantage of using flock is that locks are automatically given up when processes holding those locks go away.

Open files are identified by their file descriptors, fd. The shared flag is used to indicate that non-exclusive read locking is desired, as opposed to exclusive write locking. The wait flag indicates that the caller is willing to wait until the file is no longer locked, as opposed to failing and returning immediately.

lockdev attempts to lock a device with name gename by opening a file with the pathname /tmp/gename, and then using lockfd to lock the open file. If successful, lockdev returns a key, actually the descriptor of the open file, to be used in a subsequent call to unlockdev when unlocking the device.

Device names to use for locking are left up to applications. Applications must be careful when locking devices with many names. Device names must have length no longer than 14 characters, and cannot contain /. Devices are always locked exclusively.

lockfdpid returns the id of a process blocking a lock of a given type on an open file. Similarly, lockdevpid returns the id of a process blocking a lock of a given type on a named device. In both cases, the shared flag indicates the type of lock being blocked.

RETURN VALUES

lockfd, unlockfd, lockdev, and unlockdev all return 0 if successful. Otherwise they return -1 with the error code in UNIX errno.

lockfdpid and lockdevpid return the positive ID of a process holding a lock, or 0 if there are no processes holding a lock. If unable to tell about the lock, they return -1 with the error code in UNIX errno.

These functions do not use terrno.

ERRORS

See flock and open for errors that can occur. open errors may be encountered when trying to lock a named device.

FILES

/tmp

SEE ALSO

flock, open

NOTES

Locking across the network file system between different architectures and operating system versions causes indefinite hang-ups. Locking can be disabled by defining an environment variable NOFILELOCKS.


Last Update: $Date: 1999/05/10 20:56:51 $