[Bug 261200] Unable to pipe the output of jobs in sh

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 18 Jan 2022 18:15:15 UTC

--- Comment #5 from Ron Wills <ron@digitalcombine.ca> ---
While tracing a simple script like:

sleep 1000&
jobs | cat

I find that the first execution of jobs is executed by the shell process itself
and the second piped jobs is forked then executed in a child process. In both
cases the jobtab, found in jobs.c, has four entries in it but in the child
process all the jobs are marked unused.

In the function forkshell(), found in jobs.c, there's a section of code for the
new child process that clears the jobtab.

for (i = njobs, p = jobtab ; -- i >= 0 ; p++)
    if (p->used)

And this is the reason why jobs shows no entries when piped.

I'm not sure why this is done. I'm assuming this is possibly to prevent the
child process from doing some kind of job clean up later... I'll keep digging
into this as time permits ;)

You are receiving this mail because:
You are the assignee for the bug.