bug-bash
[Top][All Lists]
Advanced

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

Re: backgrounded children forgotten


From: Aron Griffis
Subject: Re: backgrounded children forgotten
Date: Sun, 11 Dec 2005 08:33:27 -0500
User-agent: Mutt/1.5.11

Hi Sven,

Sven Wegener wrote:     [Sun Dec 11 2005, 06:56:52AM EST]
> To me it looks like, that you can only wait for child processes that
> are still running. The backgrounded true will exit nearly
> immediately and wait can't wait for it because it has already
> terminated.

I agree that the child needs to have already exited to demonstrate the
bug, that's why I had the sleep in there.  Here is a clarification:

- This version works.  The exit status of the first subshell is
  harvested by the call to wait.

        $ cat demo-good
        #!/bin/bash
        ( exit 10 ) &
        pid=$!
        true &
        sleep 1
        wait $pid
        echo $? >&2

        $ ./demo-good
        10

- This version breaks because it is inside command substitution.  The
  exit status is lost and the error message is emitted.

        $ cat demo-bad
        #!/bin/bash
        output=$(
            ( exit 10 ) &
            pid=$!
            true &
            sleep 1
            wait $pid
            echo $? >&2
        )

        $ ./demo-bad
        ./demo-bad: line 14: wait: pid 4046 is not a child of this shell
        127

Regards,
Aron

--
Aron Griffis
Gentoo Linux Developer

Attachment: pgpMwvOOPqWIV.pgp
Description: PGP signature


reply via email to

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