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
- Next message: grocery_stocker: "Where does environ load from?"
- Previous message: Alexander Farber: "Re: pipe from child to parent: the parent exits, but the child does not"
- In reply to: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Next in thread: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Reply: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: grocery_stocker: "Where does environ load from?"
- Previous message: Alexander Farber: "Re: pipe from child to parent: the parent exits, but the child does not"
- In reply to: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Next in thread: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Reply: Alex Fraser: "Re: pipe from child to parent: the parent exits, but the child does not"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|