zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Alexy Khrabrov <deliverable@gmail.com>, zsh-users@sunsite.dk
Subject: Re: serverizing a fat process with named pipes
Date: Tue, 16 Jun 2009 17:47:45 -0700	[thread overview]
Message-ID: <090616174745.ZM32727@torch.brasslantern.com> (raw)
In-Reply-To: <7c737f300906152017m7776d596he8a1251c9e1279b8@mail.gmail.com>

On Jun 15, 11:17pm, Alexy Khrabrov wrote:
}
} I have a heavy process, an English parser loading megabytes of models,
} and then reading stdin, sentence per line, outputting the parsed text
} to the stdout.  How do I properly serverize it -- running in the
} background with <p1 >p2, those created with mkfifo p1 p2?

As PWS mentioned in his reply, the nature of FIFOs is that the reader
blocks until a writer opens it, and then the reader gets EOF when the
writer closes it (and the reader has consumed all the data).  If the
parser is designed to exit upon EOF, then you can't "serverize" it
with FIFOs without repeatedly respawning it.

If it does NOT exit on EOF, then something still needs to re-open the
FIFO each time, because once the original writer exits the reader will
always see EOF on the FIFO.

You may be able to work around this as follows:

exec {fd}>p1	# Open p1 for writing, but don't write anything
cat <p1 >p2	# Replace "cat" with your server process

Now other writers can open p1 and send lines to it and even close it
again, but "cat" never sees EOF because the shell is holding open $fd.

There are still various buffering issues including making sure that
someone is appropriately reading from p2, so you might want to look
into using inetd or the equivalent to run the process as a service
on a socket with a well-known port number instead.


      parent reply	other threads:[~2009-06-17  0:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <deliverable@gmail.com>
2005-08-10 19:18 ` rm nonexisting*; alias with parameters? Deliverable Mail
2005-08-10 20:06   ` Peter Stephenson
2005-08-10 20:31     ` Deliverable Mail
2005-08-10 22:51       ` Mikael Magnusson
2005-08-11  3:17         ` "splitting prpblem" Meino Christian Cramer
2005-08-11  8:40           ` Michal Politowski
2005-08-11 17:01             ` Meino Christian Cramer
2009-06-16  3:17 ` serverizing a fat process with named pipes Alexy Khrabrov
2009-06-16 20:29   ` Peter Stephenson
2009-06-17  0:47   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=090616174745.ZM32727@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=deliverable@gmail.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).