From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Peter C. Chapin" Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: SIGCHLD confuses popen()? Date: Wed, 29 Jan 2003 06:44:04 -0500 (EST) Sender: tru64-unix-managers-owner@ornl.gov Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: main.gmane.org 1043840578 5416 80.91.224.249 (29 Jan 2003 11:42:58 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 29 Jan 2003 11:42:58 +0000 (UTC) Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.22.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 18dqcK-0001PD-00 for ; Wed, 29 Jan 2003 12:42:56 +0100 Original-Received: (qmail 15799 invoked by uid 5); 29 Jan 2003 11:44:31 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 15790 invoked by uid 49493); 29 Jan 2003 11:44:30 -0000 Original-Received: from pchapin@ecet.vtc.edu by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.54. spamassassin: 2.50-cvs. Clear:SA:0(-4.7/5.0):. Processed in 0.438657 secs); 29 Jan 2003 11:44:30 -0000 Original-Received: from unknown (HELO emroute1.cind.ornl.gov) (160.91.4.119) by 0 with SMTP; 29 Jan 2003 11:44:30 -0000 Original-Received: from emroute1.cind.ornl.gov (localhost [127.0.0.1]) by emroute1.cind.ornl.gov (PMDF V6.1-1 #30669) with ESMTP id <0H9H00HRT4M59S@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 29 Jan 2003 06:44:30 -0500 (EST) Original-Received: from midnight.ecet.vtc.edu (midnight.ecet.vtc.edu [155.42.13.3]) by emroute1.cind.ornl.gov (PMDF V6.1-1 #30669) with SMTP id <0H9H0085Z4LR7W@emroute1.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Wed, 29 Jan 2003 06:44:19 -0500 (EST) Original-Received: (qmail 216069 invoked by uid 201); Wed, 29 Jan 2003 11:44:04 +0000 Original-Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; Wed, 29 Jan 2003 11:44:04 +0000 Original-To: Tru64 Unix Managers Xref: main.gmane.org gmane.os.tru64.managers:3120 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:3120 Thanks to Dr. Thomas Blinn for his reply. The full text of my question appears below. Here is a summary of Dr. Blinn's note: "My suspicion (and it's only a suspicion) is that when the child process is reaped, part or all of the output that has not yet been read is lost. It may be a bug in Tru64 UNIX, or it may just be good luck that it works (or at least seems to work) on some other implementations (e.g., Linux)." After reflecting on this some more it occurs to me that the difference between Tru64's behavior and Linux's behavior might be in how popen() is implemented or in how the two systems schedule processes. It seems like, in the case of Tru64, the helper process is running to completion before popen() even returns. Thus the child process is reaped (and it's output thrown away?) before the parent can read the child's output. Perhaps under Linux, popen() returns at once and the child doesn't run until its output is needed at which point it is read immediately and not lost. In any case, I suspect the observed behavior is probably in the bounds of normal on both systems. It's probably the program that is undefined. Peter -----> cut here <----- > One of my students is building a server program that installs a signal > handler for the SIGCHLD signal. The program creates a child for every > connection and then reaps the children in the signal handler (most likely > while the main loop is blocked in accept()). There are no problems with > this part. > > However, the student is also using popen() during the initialization of > the program to spawn a helper process. It happens that he is doing this > after setting up signal handling. Thus when the helper process terminates, > the SIGCHLD handler is run. This apparently confuses popen() because > subsequent attempts to read the helper process's output return nothing. > (I'm assuming the helper process terminates before popen() returns... it > produces only a single line of output and does not need to wait for > anything). However, if the signal handling is temporarly removed, the > output of the helper process can be read fine. > > The program works normally as written on our Linux system but displays the > behavior I describe here on Tru64 v5.1A. Is there some Tru64 specific > interaction between signals and popen() that we need to know about? Or > were we just lucky that it worked on Linux?