This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bash pipeline exit code - possible race condition?


> > 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]