I am writing a program to monitor serial devices (over tcp) and I use socat to link a serial device file to a tcp port as follows.
socat pty,link=/dev/ttyTCP1,raw,b19200,echo=0 tcp-listen:5001,forever,max-children=1,fork,reuseaddr
when I issue the socat command It creates /dev/ttyTCP1, my program runs, opens the file and processes data that is recieved as expected.
ps output
Code:
root 5005 1 0 18:07 pts/1 00:00:00 socat pty,link=/dev/ttyTCP1,raw,b19200,echo=0 tcp-listen:5001,forever,max-children=1,fork,reuseaddr
root 5022 5005 0 18:07 pts/1 00:00:00 socat pty,link=/dev/ttyTCP1,raw,b19200,echo=0 tcp-listen:5001,forever,max-children=1,fork,reuseaddr
If the serial device is disconnected from the network and I wait a couple of minutes the forked child process remains running and /dev/ttyTCP1 still exists.
when I plug the serial device back in I get a new PID for the child listener process.
Code:
root 5005 1 0 18:07 pts/1 00:00:00 socat pty,link=/dev/ttyTCP1,raw,b19200,echo=0 tcp-listen:5001,forever,max-children=1,fork,reuseaddr
root 5356 5005 0 18:12 pts/1 00:00:00 socat pty,link=/dev/ttyTCP1,raw,b19200,echo=0 tcp-listen:5001,forever,max-children=1,fork,reuseaddr
And the device file no long shows up using ls which is very weird since my program that has been running the whole time, which opens and keeps open the device file, can
still read new data sent by the serial device through that file.
Is this a normal behavior or am I missing something?