Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: What's a superjob?



On Wed, Sep 26, 2018 at 10:42 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> The other possibility is to immediately fork the whole function as
> soon as any non-builtin command is encountered, and then have the
> forked function fork again for the external job, to keep the process
> tree "normal".  This would simplify the job handling in the main
> shell, but ruin the intention of the function being able to affect the
> main shell context in the case where no job control ever occurs.

Hmm, now that Peter has already finished his juggling act, caught all
the clubs, and taken a bow, this suggestion may be moot, but:

Another possibility would be to always fork twice for any external job
inside a current shell construct, so we immediately end up with this:
  zsh[parent] -> zsh[superjob] -> vi[subjob]
* If subjob exits normally, so does the superjob; parent continues on
with the function/brace expression/loop/whatever.
* However, if subjob is suspended, superjob is also suspended and
changes its state such that when subjob finally exits, superjob
continues with whatever.
* In parent, if superjob is suspended, the rest of the construct is
abandoned (because we know superjob will finish it).

This wastes a fork if job control never happens, but it means the
parent only has to manage one job at a time.  The extra fork could be
skipped if job control is disabled.



Messages sorted by: Reverse Date, Date, Thread, Author