bug-bash
[Top][All Lists]
Advanced

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

Re: Strange behaviour from jobs -p in a subshell


From: Chet Ramey
Subject: Re: Strange behaviour from jobs -p in a subshell
Date: Tue, 13 Nov 2018 09:59:51 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 11/13/18 4:28 AM, Christopher Jefferson wrote:
> Consider the following script. While the 3 sleeps are running, both jobs 
> -p and $(jobs -p) will print 3 PIDs. Once the 3 children are finished, 
> jobs -p will continue to print the 3 PIDs of the done Children, but 
> $(jobs -p) will only print 1 PID. $(jobs -p) always seems to print at 
> most 1 PID of a done child.

Since the $(jobs -p) is run in a subshell, its knowledge of its parent's
jobs is transient. In this case, the subshell deletes knowledge of the
jobs it inherits from its parent, but hangs onto the last asynchronous job
in case the subshell references $!.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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