Sharing a serial port between two processes

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