in reply to Forked pipe deadlock

Keeping track of the file handles to close (or share) is probably the only way to solve the problem. Unix has a close-on-exec flag, but there's no 'close-on-fork' flag.

For more on this issue, see the thread Practice of using fork() in comp.unix.programmer.

It also includes a good discussion about what library routines might not be safe to call after using fork.