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: Håkon Bugge
Subject: Re: jobs -p falsely reports the last background pid
Date: Wed, 9 Apr 2014 14:16:22 +0200

On 9. apr. 2014, at 14.04, Greg Wooledge wrote:

> On Wed, Apr 09, 2014 at 12:43:40PM +0200, Håkon Bugge wrote:
>> This script never terminates:
>> --------------------------------------------------
>> #!/bin/bash 
>> 
>> for P in `seq 5`; do 
>>    sleep 1&
>> done
>> 
>> while true; do
>>    usleep 20000
>>    set foo `jobs -p`
>>    LEFT=$#
>>    LEFT=$[LEFT-1]
>>    echo $LEFT jobs left
>>    if [ x$LEFT = x0 ]; then
>>      break
>>    fi
>> done
> 
>>   Pasting the same commands in an interactive shell, its works.
> 
> Interactive shells enable job control (monitor mode), whereas
> noninteractive shells (scripts) do not.  If you want to use job control
> commands (like "jobs") within a script, you must enable monitor mode
> (set -m, or set -o monitor, or #!/bin/bash -m).

That is not the issue. Try it out.


Håkon





reply via email to

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