bug in pclose(3)

Brandon S. Allbery allbery at ncoast.UUCP
Tue Dec 27 07:29:40 AEST 1988


As quoted from <261 at ecijmm.UUCP> by jmm at ecijmm.UUCP:
+---------------
| I just tripped over a bug in the pclose library routine.  If you do a
| pclose on a file descriptor (that was opened with popen of course) in
| some circumstances it will hang forever.  For example:
+---------------

>From the manual page for popen(3) under System III:

	BUGS
		Only one stream opened by popen can be in use at once.

This is less a bug than a misfeature; popen() is intended for casual use, not
for complex tricks.  If BSD Unix has a way to wait for a specific process ID,
that could be used by pclose() (but I don't remember wait3() supporting
that); the alternative is to have popen()/pclose() store the PID in a linked
list, but then system() must also use that linked list -- and either new
wrappers for exec?() must be made available or the use of system()/popen()
and exec?() in the same program must be firmly discouraged.  (And then
someone will do it without reading the manual and complain about the "bug".)

Moral:  if you're going to play with multiple concurrent -- or even
potentially concurrent -- subprocesses, do all the work manually.  It takes
more work to write the program, but the result is far more robust in a multi-
process situation.

++Brandon
-- 
Brandon S. Allbery, comp.sources.misc moderator and one admin of ncoast PA UN*X
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery at hal.cwru.edu
comp.sources.misc is moving off ncoast -- please do NOT send submissions direct
      Send comp.sources.misc submissions to comp-sources-misc@<backbone>.



More information about the Comp.unix.wizards mailing list