linux   filesystem

Datei-Locking unter Linux

Ich musste wieder einmal zu oft nachlesen, welche Varianten von Datei-Locking es unter Linux gibt und was die Stolperfallen sind.

Variante POSIX Lock BSD Lock Linux Open File Description Locks
Range Byte File Byte
Owner Process File File
Issues - not fork() save - not thread save - released on first close() - exclusive not fork() save - not NFS save - sometimes implemented through fcntl() Linux 3.15+
C-API fcntl(fd, F_{GETLK,SETLK,SETLKW}, struct flock *), lockf(fd, F_{LOCK,TLOCK,ULOCK,TEST}, len) flock(fd, LOCK_{SH,EX,UN} fcntl(fd, F_OFD_{GETLK,SETLK,SETLKW}, struct flock *)

Literatur zum nach-/weiterlesen:

Written on November 27, 2017