On 5/5/22 7:46 AM, Geoff Clare via austin-group-l at The Open Group wrote:
[Robert intended to send the mail I'm replying to to the list, but it
was only sent to me. I've quoted it in full.]

Robert Elz <k...@munnari.oz.au> wrote, on 05 May 2022:

This leaves just bash of the shells I have to test.   bash is odd, at
first glance it seems to act like the ksh's, zsh & fbsh do.   But it
doesn't.   This seems to be because in a pipeline like

        sleep 20 | sleep 20 &

creates a subshell for the '&' first, and then creates a new subshell
environment for each side of the pipe.   None of the other shells do that,
the processes in the pipeline are in subshell environments (in most anyway)
but the same one as the one created for the async process execution - that
is, the sleep processes are direct children of the parent shell, not
grandchildren as they are in bash.

When given "kill %1" it then seems to work just like those other shells, but
all that is actually killed is the forked copy of itself, leaving the sleep
processes running, orphaned.

Show your work.

I tested this on macOS 12 and RHEL 7, using interactive shells with job
control enabled, running the latest bash devel version, and could not
reproduce it.

The Linux version of pstree shows the process group; the macOS version
doesn't have that option. Both show the sleep processes are direct
descendents of the parent shell, but even if they aren't, bash clearly does
not leave the sleep processes orphaned.

macOS 12:

$ sleep 20 | sleep 20 &
[1] 16711
$ pstree $$
-+= 16694 chet ./bash
 |--= 16710 chet sleep 20
 |--- 16711 chet sleep 20
 \-+= 16712 chet pstree 16694
   \--- 16713 root ps -axwwo user,pid,ppid,pgid,command
$ kill %1
$ ps axuw | grep sleep
chet 16717 0.0 0.0 34142704 632 s027 U+ 11:04AM 0:00.00 grep sleep
[1]+  Terminated: 15          sleep 20 | sleep 20

RHEL 7:

$ sleep 20 | sleep 20 &
[1] 106739
$ pstree -g $$
bash(106427)─┬─pstree(106743)
             ├─sleep(106738)
             └─sleep(106738)
$ kill %1
$ ps axuw | grep sleep
chet     106753  0.0  0.0 112812   960 pts/1    R+   10:59   0:00 grep sleep
[1]+  Terminated              sleep 20 | sleep 20

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

          • Re:... Chet Ramey via austin-group-l at The Open Group
          • Re:... Robert Elz via austin-group-l at The Open Group
            • ... Chet Ramey via austin-group-l at The Open Group
      • Re: When ca... Geoff Clare via austin-group-l at The Open Group
        • Re: Whe... Chet Ramey via austin-group-l at The Open Group
          • Re:... Geoff Clare via austin-group-l at The Open Group
            • ... Chet Ramey via austin-group-l at The Open Group
              • ... Steffen Nurpmeso via austin-group-l at The Open Group
              • ... Geoff Clare via austin-group-l at The Open Group
              • ... Chet Ramey via austin-group-l at The Open Group
        • Re: Whe... Chet Ramey via austin-group-l at The Open Group
        • Re: Whe... Robert Elz via austin-group-l at The Open Group
          • Re:... Chet Ramey via austin-group-l at The Open Group
          • Re:... Robert Elz via austin-group-l at The Open Group
        • Re: Whe... Robert Elz via austin-group-l at The Open Group
          • Re:... Chet Ramey via austin-group-l at The Open Group
    • Re: When can sh... Chet Ramey via austin-group-l at The Open Group
  • Re: When can shells ... Chet Ramey via austin-group-l at The Open Group

Reply via email to