unix - Prevent FIFO from closing / reuse closed FIFO -


consider following scenario:

a fifo named test created. in 1 terminal window (a) run cat <test , in (b) cat >test. possible write in window b , output in window a. possible terminate process , relaunch , still able use setup suspected. if terminate process in window b, b (as far know) send eof through fifo process , terminate well.

in fact, if run process not terminate on eof, you'll still not able use fifo redirected process. think because fifo considered closed.

is there anyway work around problem?

the reason why ran problem because i'd send commands minecraft server running in screen session. example: echo "command" >fifo_to_server. problably possible using screen i'm not comfortable screen think solution using pipes simpler , cleaner one.

a reading file. when reaches end of file, stops reading. normal behavior, if file happens fifo. have 4 approaches.

  1. change code of reader make keep reading after end of file. that's saying input file infinite, , reaching end of file illusion. not practical you, because you'd have change minecraft server code.
  2. apply unix philosophy. have writer , reader don't agree on protocol, interpose tool connects them. happens, there such tool in unix toolbox: tail -f. tail -f keeps reading input file after sees end of file. make clients talk pipe, , connect tail -f minecraft server:

    tail -n +1 -f client_pipe | minecraft_server & 
  3. as mentioned jilles, use trick: pipes support multiple writers, , become closed when last writer goes away. make sure there's client never goes away.

    while true; sleep 999999999; done >client_pipe & 
  4. the problem server fundamentally designed handle single client. handle multiple clients, should change using socket. think of sockets “meta-pipes”: connecting socket creates pipe, , once client disconnects, particular pipe closed, server can accept more connections. clean approach, because ensures won't have mixed data if 2 clients happen connect @ same time (using pipes, commands interspersed). however, require changing minecraft server.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -