What is the best practice for locking serial ports and other devices in Linux?

前端 未结 1 1199
花落未央
花落未央 2020-12-11 03:59

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

相关标签:
1条回答
  • 2020-12-11 04:59

    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.

    0 讨论(0)
提交回复
热议问题