delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/30/11:10:39

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Date: Thu, 30 Jul 2009 15:10:19 +0000 (UTC)
From: Eric Blake <ericblake AT comcast DOT net>
To: David Antliff <david DOT antliff AT gmail DOT com>
Cc: cygwin AT cygwin DOT com
Message-ID: <1809717448.6734781248966619380.JavaMail.root@sz0059a.emeryville.ca.mail.comcast.net>
In-Reply-To: <770992004.6687041248959361064.JavaMail.root@sz0059a.emeryville.ca.mail.comcast.net>
Subject: Re: bash pipeline exit code - possible race condition?
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

> > I tried to reproduce on Linux but without success - did you simply
> > run
> > my script or perhaps something else? Do you see error "141" as
> well?
> 
> Status 141 is from SIGPIPE.  Basically, it happens when the read end
> of the
> pipe exits before the writer.  It is not specific to cygwin, but may
> occur
> more frequently on cygwin since cygwin has different scheduling than
> Linux.  It is not an error in the OS - if you are going to worry
> about
> the exit status of all processes in a pipeline, then you must be
> prepared
> to deal with the earlier processes ending abruptly because the later
> processes aren't interested in any more data.

Or, rewrite your script to not trigger early exit in the first place.

For example,

make --version | sed -n 1p

forces sed to process every line of the make output, rather than exiting
after the first line is printed, and thus eliminates the possibility of
sed exiting before make has had a chance to output all its --version output
into the pipe, thus making it so make never sees a SIGPIPE.

-- 
Eric Blake

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019