bug-bash
[Top][All Lists]
Advanced

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

Re: Bug: different behavior between "jobs -l" and "builtin jobs -l"


From: Chet Ramey
Subject: Re: Bug: different behavior between "jobs -l" and "builtin jobs -l"
Date: Tue, 21 Mar 2017 11:12:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 3/20/17 7:47 PM, Hengyang Zhao wrote:
> Hello,
> 
> I am experiencing an unexpected behavior when using "builtin jobs -l". It
> seems that it's output fd is not as same as "jobs -l" without the builtin
> prefix. So when I piped it into wc, I got different results (as seen in the
> code I pasted below).
> 
> Bash version: GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu)
> OS: Fedora 25, kernel 4.9.13-200.fc25.x86_64
> 
> Buggy behavior:
> when we have one or more background processes:
> jobs -l | wc        # produces 0 0 0
> builtin -l | wc              # produces non-zero non-zero non-zero

(This is actually the opposite of what happens, as shown by your examples
below.)

> I tried to fix the bug, but after I looked at the code, the jobs printing
> procedure clearly prints to stdout. So I think it's not a easy work to
> track down the bug.

It's not a bug.  The first part of a pipeline is always run in a subshell.
That subshell doesn't really have any jobs, since none of the parent's
jobs are children of that shell -- you can't wait for them, for instance.

There is special-case code that attempts to detect when the `jobs' builtin
is running (execute_cmd.c:execute_subshell_builtin_or_function) and doesn't
remove the jobs from the jobs table in that one case, specifically to allow
the output of `jobs' to be piped.  Running the `builtin' builtin defeats
that.

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



reply via email to

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