I have a problem that I can't seem to solve involving two named pipes. Basically, I have two processes that I don't have control over. They are communicating via named pipes (
mknod pipe p). Process one is a GPS driver that outputs messages in NMEA0183 format. Process two is a navigation application that reads NMEA0183 data to get location and date/time from GPS. I need to adjust this data (reason: google for WNRO or ask).
First process is continuously writing data (~5-8 lines of text) in 1 second intervals into /var/run/one.pipe and leaving it there until it is read(?)
Second process is reading this data from the named pipe. I can change the name of the named pipe to read from. I changed it to /var/run/two.pipe
The final goal is to read data from one.pipe, do some processing, and then pass it to two.pipe. However, for the meantime and for testing I am just trying to copy the data one by one from one.pipe to two.pipe. I figured it's not feasible wasting time on the whole processing until I can manage to complete this (simpler?) task.
A very simple shell script works: copy.sh
#!/bin/sh cat one.pipe > two.pipe &
Now I captured some of the data that the source process writes to
one.pipe and tried to manually write it to
two.pipe to be read by the reading process:
#!/bin/sh while true; do echo "\$GPGGA,,,,,,,,*12" > two.pipe echo "\$GPGSA,,,,,,,,*23" > two.pipe echo "\$GPRMC,,,,,,,,*34" > two.pipe echo "\$GPGSV,,,,,,,,*45" > two.pipe echo "\$GPGSV,,,,,,,,*56" > two.pipe echo "\$GPGSV,,,,,,,,*67" > two.pipe # checksums (*xx) are just examples here sleep 1 > two.pipe done
Now this doesn't work well. If I compare
cat one.pipe vs.
cat two.pipe I can see that the messages in
two.pipe don't "pile up", while they do from the original process, that writes into
one.pipe. E.g., if I start my script, it should write to the named pipe and continue to do so on and on. When I read that pipe with
cat it should output all the data so far (assuming the fifo-buffer hasn't been filled yet). It is first-in-first-out afterall, isn't it?!
Also, cat now frequently stops seemingly randomly. And finally, also the process that I can't control which is reading from
two.pipe seems to not work well with the data/causes the script to terminate.
I don't even understand why the script terminates, even though it contains an infinite loop?!
What am I overseeing here? If this is not feasible to write in shell, C would also be an option.