bug-bash
[Top][All Lists]
Advanced

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

Re: jobs -p falsely reports the last background pid


From: Pierre Gaston
Subject: Re: jobs -p falsely reports the last background pid
Date: Wed, 9 Apr 2014 15:32:08 +0300

On Wed, Apr 9, 2014 at 3:28 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:

> On Wed, Apr 09, 2014 at 02:16:22PM +0200, Håkon Bugge wrote:
> > That is not the issue. Try it out.
>
> Very well.  I can confirm that this script does not terminate on HP-UX
> 10.20 under bash 4.3.8:
>
> #!/bin/bash
> set -m
> for x in 1 2 3 4 5; do sleep 1 & done
> while jobs=$(jobs -p)
>       echo "jobs left: <$jobs>"
>       [[ $jobs != "" ]]
> do
>     sleep 1
> done
>
> As a workaround, you could consider using "wait" instead of this polling
> loop to detect the termination of child processes.  This script, for
> example, properly waits and terminates:
>
> #!/bin/bash
> set -m
> for x in 1 2 3 4 5; do sleep 1 & done
> wait
>

The rationale of sus seems to say that it should also work without set -m

"The jobs utility is not dependent on the job control option, as are the
seemingly related bg and fg utilities because jobs is useful for examining
background jobs, regardless of the condition of job control. When the user
has invoked a set +m command and job control has been turned off, jobs can
still be used to examine the background jobs associated with that current
session. Similarly, kill can then be used to kill background jobs with kill
%<background job number>. "


reply via email to

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