Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14811

Re: Strange behaviour from jobs -p in a subshell

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Strange behaviour from jobs -p in a subshell
Date Tue, 13 Nov 2018 10:09:41 -0500
Lines 19
Approved bug-bash@gnu.org
Message-ID <mailman.3981.1542122776.1284.bug-bash@gnu.org> (permalink)
References <b17b162c-9f60-37fc-2473-30e267a681d2@st-andrews.ac.uk> <563c6188-c905-db81-f330-b79bf17e4413@case.edu>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1542122777 7815 208.118.235.17 (13 Nov 2018 15:26:17 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
Mail-Followup-To bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <563c6188-c905-db81-f330-b79bf17e4413@case.edu>
User-Agent NeoMutt/20170113 (1.7.2)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From 139.137.100.1
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14811

Show key headers only | View raw


On Tue, Nov 13, 2018 at 09:59:51AM -0500, Chet Ramey wrote:
> 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

If the goal is to obtain the result of "jobs -p" and use it in a script,
I would suggest redirecting the output of jobs -p to a temp file, then
reading it.  That skips the subshell.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Strange behaviour from jobs -p in a subshell Greg Wooledge <wooledg@eeg.ccf.org> - 2018-11-13 10:09 -0500

csiph-web