File locking in Linux

File locking is a mutual-exclusion mechanism for files. Linux supports two major kinds of file locks: advisory locks mandatory locks Below we discuss all lock types available in POSIX and Linux and provide usage examples.


Reusing UNIX domain socket (SO_REUSEADDR for AF_UNIX)

Unix domain sockets are a networkless version of Internet sockets. They have several advantages: Unix domain sockets are files, so file-system permissions may be used for them when one end is closed (e.g. process exits), SIGPIPE is delivered to another end performance may be up to 2x better See details here.