------------------------------------------------------------------------------- File/Resource Locking See also perl/lock.hints and shell/file.hints ------------------------------------------------------------------------------- File Locks NOTE: C and UNIX does not stop a program from accessing a file, all lock methods only work if all processes using the file use the same locking method. Usually this is by only one program but not always (EG: the passwd command with the /etc/passwd file). 1/ flock() (BSD) is totally unreliable accross hosts. 2/ lockf() (SysV) but appears to be NFS-specific it is actually and interface to the file locking functions fcntl(). This may or may not be available on your host. 3/ fcntl lock protocol is NFS complient but not always available 4/ Create a lock file (open with create exclusive flags) Works from NFS version 3 will not work for root without exclusive. 5/ rename() a file. This should be atomic in all file systems Basically create a unique file and then try to rename it to the file lock. However internally it is really an atomic hard-link and a remove 6/ Create a hard file link. Essentually create a new directory entry which much be atomic (at some low level point) in all file systems. 7/ Create a symbolic file link. Works for root, BSD, SysV, but unknown about NFS atomic -------------------------------------------------------------------------------