Sharing a serial port between two processes
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Track title: CC E Schuberts Piano Sonata D 784 in A
--
Chapters
00:00 Sharing A Serial Port Between Two Processes
00:35 Accepted Answer Score 5
01:28 Thank you
--
Full question
https://superuser.com/questions/488908/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #serial
#avk47
ACCEPTED ANSWER
Score 5
In linux it always was a problem to get exclusive access to the serial ports as the only way to restrict unwanted interferention is the user/group access rights.
With time the convention had been established how to tell the other processes not to open the serial port device when some process is willing to 'own' it: the process that is going to open the serial (parallel) port first check for lock file in the /tmp
directory (other standards may use /var/lock
directory), for example /tmp/LCK..ttyS0 in case of the ttyS0 device and writes its PID
into that file. Then it reads it back and if the PID
matches then the process took the ownership of the port. After the port is not needed any more the lock file is deleted by the process.
Thus you may open it from different processes provided these processes uids or gids has rw access on the device