Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As it is not possible to directly share a serial port between two processes using Linux, I am looking for another way to achieve this, I have heard about socat but could not find a concrete example of how to realize the following:

Split one physical serial port (/dev/ttyUSB0) into two virtual ports, one for reading and one for writing, as one process only needs to send data, and one only needs to receive data.

I can no modify the sending application unfortunately.

share|improve this question
3  
"As it is not possible to directly share a serial port between two processes" Why do you think so? –  Serge Oct 17 '12 at 12:15
    
multiple sources (such as stackoverflow.com/questions/8745948/…) confirm this , but if it's possible anyway, please tell me ;) –  peterrus Oct 17 '12 at 16:24
    
did you note the edit to the question you referred: "Edit -- This needs to work on Windows, but Mac and Linux would also be nice." The answer was given for the Windows case. 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, so the convention had been established with time how to tell other processes not to open the serial port device when some process is willing to 'own' it. So you may open it from different processes provided the processes uids or gids has rw access on it –  Serge Oct 18 '12 at 1:34
    
So you are simply stating that I can in fact access a serial device from multiple processes? If so, please post it as an answer, I will test it somewhere after the weekend probably, but then you will get your mark ;) –  peterrus Oct 18 '12 at 8:27
    
Yes. That's correct –  Serge Oct 18 '12 at 15:44

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
I have /dev/ttyACM0 (an usb serial port) accessed by one proces that writes data to the port. I have another process (screen /dev/ttyACM0 9600) that should read data from the port. Nothing is being printed to the screen however. –  peterrus Dec 8 '12 at 13:32
    
Must have had something to do with screen wanting to use flow control I suppose, when using a simple cat /dev/ttyACM0 everything works fine! –  peterrus Dec 8 '12 at 13:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.