Re: Issues with job control and nested shell processes

Details
Message ID
<e8nOBpFFS9HeItSM0Wq2u0LKgHfRCVAOn3x2B71-pQthA-qHpOHp3N7Zbb0TO1I9kZaV_t3GYiRi0cAgDPIhyKI8L69b2Un937l-heMoEgo=@emersion.fr>
DKIM signature
pass
Download raw message
On Wednesday, June 5, 2019 4:41 PM, Drew DeVault <sir@cmpwn.com> wrote:
> $ sleep 30 &
> $ pstree -a $(pgrep mrsh | head -n1)
> mrsh
> ├─mrsh
> │ └─sleep 30
> └─pstree -a 10634

Hmm. So, I'm not sure whether this is an optimization that dash
implements or whether this is really required by the spec.

Basically, the issue is that the `&` is represented very high in the
POSIX shell AST. So the job that needs to be run may actually need that
extra shell process, for instance if the asynchronous command contains
`&&` or `|`:

$ sleep 30 &
program
└─command_list & ─ pipeline
  └─simple_command
    ├─name ─ word_string [0:0 → 0:5] sleep
    └─argument 1 ─ word_string [0:8 → 0:8] 30
$ echo a && sleep 30 &
program
└─command_list & ─ binop &&
  ├─pipeline
  │ └─simple_command
  │   ├─name ─ word_string [0:0 → 0:4] echo
  │   └─argument 1 ─ word_string [0:6 → 0:6] a
  └─pipeline
    └─simple_command
      ├─name ─ word_string [0:10 → 0:15] sleep
      └─argument 1 ─ word_string [0:18 → 0:18] 30