Return to BSD News archive
Xref: sserve comp.unix.ultrix:17097 comp.unix.programmer:8700 comp.unix.bsd:11729 Newsgroups: comp.unix.ultrix,comp.unix.programmer,comp.unix.bsd Path: sserve!newshost.anu.edu.au!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!coil!news.nist.gov!przemek From: przemek@rrdstrad.nist.gov (Przemek Klosowski) Subject: Peculiar behavior of pclose()---bug on at least two Unixes? Message-ID: <PRZEMEK.93Mar28212112@rrdstrad.nist.gov> Sender: news@nist.gov Organization: U. of Maryland/NIST Date: Mon, 29 Mar 1993 02:21:12 GMT Lines: 54 Hello! This is a repost of an article I posted about a week ago, but it didn't seem to get out into the net---however, I apologize if you do see it for the second time. I came across a peculiar behavior of pclose(); when only one file is popen()'ed, everything works as the man page and Stevens' book claim: pclose() closes the pipe and kills the child process. However, if two filehandles are popen()'ed, the subsequent pclose() never returns (on Ultrix it sits forever in wait()). Does anyone have an idea what causes it and how to get around it? This behavior has been checked on ConvexOS and Ultrix 4.3. I enclose a short program demonstrating this behaviour. przemek klosowski (przemek@rrdstrad.nist.gov) Reactor Division (bldg. 235), E111 National Institute of Standards and Technology Gaithersburg, MD 20899, USA (301) 975 6249 ------------------------cut here------------------------------------- #include <stdio.h> int main(){ FILE * fp1, *fp2; /* this works fine (it better!!!) */ fp1 = popen ("cat","w"); fprintf (fp1,"This is output to first filehandle \n"); fflush (fp1); pclose(fp1); /* this is broken (nobody ran two filters at the same time, eh?) */ fp1 = popen ("cat","w"); fp2 = popen ("cat","w"); fprintf (fp1,"This is output to first filehandle\n"); fflush (fp1); fprintf (fp2,"This is output to second filehandle\n"); fflush (fp2); pclose(fp1); /* this call never returns */ pclose(fp2); } -- przemek klosowski (przemek@rrdstrad.nist.gov) Reactor Division (bldg. 235), E111 National Institute of Standards and Technology Gaithersburg, MD 20899, USA (301) 975 6249