Reputation: 5821
I develop an emulator for a serial device and to that end use the /dev/ptmx
interface to create a pseudoterminal master descriptior and a corresponding slave in /dev/pts/XX
. Everything works until the client which opened /dev/pts/XX
closes it. Then the master descriptor apparently gets closed too. Is there a way to make the master fd survive across client re-connections? I need a server process which can continue serving its client which can come and go.
If there's a better way to have an emulated serial device, hints are very welcome too!
Upvotes: 1
Views: 208
Reputation: 5821
Make the server itself open the slave in O_WRONLY
mode and keep the resulting fd for as long as the server is serving. It appears that slave ptys can be opened multiple times and are reference-counted, so as long as the server keeps one open, other processes can open and close it any number of times.
Upvotes: 1