Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14818 > unrolled thread
| Started by | Christopher Jefferson <caj21@st-andrews.ac.uk> |
|---|---|
| First post | 2018-11-14 09:48 +0000 |
| Last post | 2018-11-14 09:48 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Strange behaviour from jobs -p in a subshell Christopher Jefferson <caj21@st-andrews.ac.uk> - 2018-11-14 09:48 +0000
| From | Christopher Jefferson <caj21@st-andrews.ac.uk> |
|---|---|
| Date | 2018-11-14 09:48 +0000 |
| Subject | Re: Strange behaviour from jobs -p in a subshell |
| Message-ID | <mailman.4028.1542188959.1284.bug-bash@gnu.org> |
On 13/11/2018 14:59, 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 $!. Is this a case of "works as intended" then? I find the current behaviour very strange -- I could understand if 'jobs -p' showed no information about processes spawned from the parent shell, or all of it, but the current position seems quite inconsistent. This originally came up as I was implementing a poor way of limiting how many background processes I spawn, by doing: while (( $(jobs -p | wc -l) >= $JOBCOUNT )) do sleep 1 done Here, the $(jobs -p | wc -l) decreases to 1 as jobs finish, but never reaches 0. I've now changed 'sleep 1' to 'jobs > /dev/null; sleep 1'. I can't find any documentation that says this, but it seems 'jobs' will clean up children which are done, which 'jobs -p' does not (this makes sense of course, as jobs -p doesn't report if a child is done, but I still can't find it documented anywhere). Chris
Back to top | Article view | gnu.bash.bug
csiph-web