The goal is to \"lock\" access to a serial device or other Linux device, to ensure exclusive access to the device while it\'s in-use. This prevents, for example, two program
As far as I can tell, using flock() locking of serial ports or other devices is probably the best the way to go in Linux, following Debian's lead in Debian bug #734086. Note that the original advocate of this Debian change, Roger Leigh, has moved away from Debian and Linux and onto FreeBSD in 2014/2015 (see his comments here). But Debian seems to be sticking with the flock()
method, so that's worth something.
However given how poorly this change has been communicated to the broader Linux community at this point, it could be good to support the older SYSV-style UUCP device lock files (/var/lock/LCK..ttyS1
) as a compile-time option, for use in systems still using the older lock method.
E.g. picocom has now changed to using the flock()
method, with a compile-time optional selection of SYSV-style UUCP device lock files.
I'd like to submit an update to the Serial HOWTO regarding this (since it's the first Google search result for "Linux serial lock"), but right now it's difficult to update documents on the LDP website due to its current maintenance state.