The question is published on by Tutorial Guruji team.
I have 2 applications, one written in C and the other in JAVA. Lets call these applications ‘C’ and ‘JAVA’.
- C Creates a named pipe via mkfifo (have also tried mknod – no difference to the outcome)
- C forks off with the child process invoking a system() call to fire-up the JAVA application, passing to it, the name of the FIFO file. IE: system(“name-of-java-app ‘name-of-fifo-file'”)
- C parent opens the FIFO for write only
JAVA opens the FIFO for read.
- C sends a ‘handshake’ message to the FIFO via write().
- JAVA receives ‘handshake’
- C then tries to send subsequent messages to JAVA, via the FIFO.
Here is where it get weird. Unless C closes (not removes) the FIFO FD or if the parent process terminates, JAVA will not read from the FIFO. If C sends ‘handshake’ then closes, all is well and as expected.
If C then re-opens the FIFO, sends a ‘message’ to JAVA then C closes, JAVA will read it.
From all of the examples of FIFO between C and JAVA that I have studied, they only include a single transfer of data. IE, open, write/read, close but not a continuing stream from source to destination, as I require.
Implementing an ‘open, read/write, close’ at each end works but surely, there must be a better/more efficient method – more congruent to the ethos of pipes. If so, I would greatly appreciate any input!
JAVA’s readline expects either ‘r’ or ‘n’ to terminate a string. Coming from a UNIX C environment (where one expects ‘