How to read serial port by multiple applications and get all the data in both?

I'm working with a GPS receiver that is visible as a serial device. I have successfully attached it as the source to ntpd, which is the main goal.

Now I need to add some sort of state monitoring (I've already written an app that reads GPS stream and displays various quality stats to LCDd). The problem is that these applications steal each other's data: ntpd starts first and gets most of the stream (which is good) and monitoring app gets just scraps of the data (which is bad).

I can:
  • Write a simple application that opens GPS and passes the data to a pair (or more) Unix streams (sort of device-wise tee)
  • Modify my app to create additional socket to pass copy of data there. Which looks like an ugly hack and I'm not sure what happens, when ntpd will start with missing gps device that will appear later.
My question is: Is there either a ready command to split character device into two, with copy of the stream in each or is there any ioctl/open flag that will tell apps to read, don't steal data?
 
Couldn't you use named pipes along with tee? Something like
mkfifo stream0 stream1
tee stream0 stream1 < /dev/cuau0 > /dev/null &
Then give ntpd stream0 and LCDd stream1.
 
Back
Top