bug-bash
[Top][All Lists]
Advanced

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

Strange behaviour from jobs -p in a subshell


From: Christopher Jefferson
Subject: Strange behaviour from jobs -p in a subshell
Date: Tue, 13 Nov 2018 09:28:46 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

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.


#!/usr/bin/bash

(sleep 2 ) &
(sleep 2 ) &
(sleep 2 ) &

while /bin/true
do
     echo A
     echo $(jobs -p)
     echo B
     jobs -p
     echo C
     sleep 1
done


reply via email to

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