LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2018, 01:19 PM   #1
crabbit
LQ Newbie
 
Registered: Feb 2018
Posts: 13

Rep: Reputation: Disabled
Weird socat behavior for linked serial device file.


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?
 
Old 03-28-2018, 02:03 PM   #2
crabbit
LQ Newbie
 
Registered: Feb 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
found my own answer...

If the file is deleted, the file handle remains open and can still be used (This is not what some people expect). The file will not really be deleted until the last handle is closed.

Further, socat does not actually create a "file", it creates a symlink to a /dev/pts
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using serial device file to connect a lcd display sharan013 Linux - Embedded & Single-board computer 4 03-16-2012 04:14 PM
weird behavior of log file JTS911 Linux - Newbie 5 10-11-2011 09:22 PM
Weird behavior with grep - getting ^M in output when they are not in the file Stephanie Seney Programming 1 10-04-2011 12:21 PM
[SOLVED] C++ - LibSerial with socat virtual serial port problems golmschenk Programming 4 10-18-2010 04:30 PM
Weird behavior!! surfer41 Linux - Networking 1 04-25-2006 07:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration