Re: pipe from child to parent: the parent exits, but the child does not

From: Alexander Farber (Alexander.Farber_at_gmail.com)
Date: 08/24/05


Date: 24 Aug 2005 07:21:24 -0700

Alex Fraser wrote:
> "Alexander Farber" <Alexander.Farber@gmail.com> wrote in message
> news:1124878926.938414.180530@f14g2000cwb.googlegroups.com...
> > And more interesting to me: why doesn't the pipe
> > fill up and the write() block? Who is reading it?
>
> It will fill up... eventually (try removing the sleep(1)).

Yes, you're right here too - I removed the sleep(1) and increased
the sleep() interval in the parent and the write()s in the children
did start blocking after some time.

> With regard to the actual problem you are trying to solve: writing up to
> PIPE_BUF (>= 512) bytes to a pipe is atomic; write() will write either all
> or nothing (whether blocking or not), and the bytes will not be interleaved
> with other writes to the same pipe. However, it isn't guaranteed that read()
> will return data from just one write(), or all the data from one write().
> This means that if the writes are small and (for example) you use a suitable
> delimiter, you can have all children write to the same pipe.

I wonder actually what design is better - the one like I have now:

1) Many forked children, each with an own pipe (child -> parent),
which I put into a struct pollfd and monitor with poll().

2) Or what you suggest: one pipe for all, since the messages written
by children are small (3 ints) and putting just that 1 pipe fd into
the struct pollfd.

The problem with the second approach is that I would have to write()
a host id together with the message. Ok, just write one more int
additionally to the 3 ints above... But then I'd have to run through
my singly-linked list of hosts to locate that one host.... (Ok, I could
switch from a singly-linked list to a dynamically allocated array...)

I wonder, what would be the benefit from having just one pipe for
all...

Regards
Alex



Relevant Pages

  • Re: pipe from child to parent: the parent exits, but the child does not
    ... > which I put into a struct pollfd and monitor with poll. ... > 2) Or what you suggest: one pipe for all, ... > a host id together with the message. ... a third alternative is a small number of child "worker" ...
    (comp.unix.programmer)
  • Re: Watchguard Firebox Peak - Force traffic through a specific connection?
    ... We setup a route to the host through a specific pipe (Cable Modem), ... Modem connection, and DSL connection. ...
    (comp.security.firewalls)
  • Re: [Full-disclosure] n3td3v group calls on RSA to clarify their stance
    ... You'd be amazed at what one host can do, given an actual pipe bigger than ... Several tens of thousands of bogus entries per day till it ... packets, over a 24 hour timespan that's only one or two packets per second. ...
    (Full-Disclosure)
  • Re: named pipes
    ... another computer i had to change the pipe name when i open the pipe. ... If you don't specify an explicit host name, ... DosOpen is going to look for the pipe on the current host, ... If you don't specify an explicit drive letter, ...
    (comp.os.os2.programmer.misc)
  • Re: interconnection between two processes
    ... > I'm considering now what mechanisms to use for interconnection between 2 ... > the same host. ... Really depends how they're supposed to communicate. ... Closing the pipe can be the signal for the other process to exit. ...
    (comp.unix.programmer)