[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Several issues with coprocesses regarding exit status

From: Chet Ramey
Subject: Re: Several issues with coprocesses regarding exit status
Date: Thu, 13 Dec 2012 15:42:30 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 12/11/12 2:31 PM, DJ Mills wrote:

The first two have been covered in other messages.

> 3)
>   The first two issues aren't THAT big of a deal, because you can simply not
>   worry about coproc's exit status and use wait's.

That's the idea; the coproc command itself returns an indication of whether
or not the process to execute the command was created successfully.

> That leads me to the
> third
>   and largest issue, which is that "NAME_PID" only appears to work properly
>   either when in an interactive shell or when there's no command between the
>   coproc and the wait.

It's a race to see whether or not the coprocess exits and is reaped and
cleaned up before wait executes.  `false' is a very short-lived process,
doesn't require an exec, and so I would expect the child to exit very
quickly.  The cleanup, which includes unsetting the coproc-specific
variables, happens when the coprocess is reaped, not when the next one is

You can avoid the error by using something like
[ -n "$COPROC_PID" ] && wait "$COPROC_PID"

but of course you lose the exit status that way.

I will look at saving the coprocess pids in the shell's list of exited
background jobs (or see whether they're being saved there already), so
if you manage to save the coproc pid you will be able to find the exit

There are also some race conditions with coproc creation and very short-
lived processes; look at
for some additional details.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]