[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fork & write stdout, menu, bug 42051



Hi.

On Wed, Jul 28, 1999 at 06:51:14PM +0200, joost witteveen wrote:
> However, the problem with that is that the exit(0) in the parent may
> well happen before the child wrote to stdout. So, users will see the
> output of the child printed mingled with the output of dpkg. To
> prevent that, I made the child send a signal to the parent after it
> has printed to stdout, and before it starts waiting for dpkg. The
> parent has a signal hadnler for the sent signal that will call
> exit(0), and will not exit before it recieves the signal.

My suggestion: Create a pipe for the communication. Do not actually
send any data down it. Each of parent and child close half the pipe as
usual (for one way communication) (maybe skip this?). Then the parent
waits, by reading the pipe (and blocking). The child signals it by
closing the pipe (and the read returns 0). If the child dies, the pipe
is also closed, so long as the child guarantees to close the pipe,
there will be no deadlock. Sorry, no code, but I think this is
straightforward enough if you have ever used pipes with fork. If you
want, I can dig out some code that does this.

Giuliano.


Reply to: