redirecting standard i/o from an exec'ed programme
Maarten Litmaath
maart at cs.vu.nl
Fri Aug 17 04:53:10 AEST 1990
In article <410 at sun13.scri.fsu.edu>,
mayne at VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) writes:
)...
) /* Close unused pipes */
) close (TOCHILD);
) close (FROMCHILD);
) /* Change stdin and stdout to pipe */
) close(0);
) dup(FROMPARENT);
close(FROMPARENT); /* !!! */
) close(1);
) dup(TOPARENT);
close(TOPARENT); /* !!! */
I've deleted the rest of the code, but there were still a few other places
where calls to close() should be added.
Always close every unused file descriptor (esp. when dealing with pipes),
else you will get bitten one day; example scenario:
- the child exits
- the parent reads from the pipe to the child
- the parent still has the write side of the pipe open
- the read hangs...
--
"UNIX was never designed to keep people from doing stupid things, because
that policy would also keep them from doing clever things." (Doug Gwyn)
More information about the Comp.unix.questions
mailing list