[Top][All Lists]

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

Re: jobs -p falsely reports the last background pid

From: Chet Ramey
Subject: Re: jobs -p falsely reports the last background pid
Date: Thu, 10 Apr 2014 11:14:20 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 4/9/14, 6:43 AM, Håkon Bugge wrote:

> Bash Version: 4.2
> Patch Level: 45
> Release Status: release
> Description:
> This script never terminates:

Bash holds on to processes and their status until it's notified the user
about the status of terminated processes.  It's especially careful to hold
onto the status of the current job (the last background job started) until
the user's been notified.  It seems like you're making unwarranted
assumptions about what `jobs -p' will return.

You have a couple of choices:

1.  Use `wait', which, as Greg suggested, is much better suited for this

2.  Since you're interested in running jobs, ask for running jobs using
    `jobs -rp' instead of running `jobs -p' and assuming things about the

3.  Throw a call to `jobs' in there so the shell thinks it's notified the
    user about terminated jobs.  This is essentially the reason that it
    `works' in an interactive shell: the shell does the notification about
    terminated jobs asynchronously when it's interactive.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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