zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: <zsh-workers@zsh.org>
Subject: Re: What's a superjob?
Date: Wed, 26 Sep 2018 16:50:53 +0100	[thread overview]
Message-ID: <20180926155055eucas1p2a9eeba9267adcb603fbd609e47780010~X-fvU7i_h1255912559eucas1p2q@eucas1p2.samsung.com> (raw)
In-Reply-To: <1537975883.2212216.1521491576.1CF7021B@webmail.messagingengine.com>

On Wed, 26 Sep 2018 15:31:23 +0000
Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> Could someone explain in a sentence what a 'superjob' is?

Not in a sentence, no.

> I'm guessing that it's the 'bodyguard shell' demonsrated in
> Joey's 43506 and explained in 43514.  Is that correct?

Yes, basically, if you mean what I think you mean.

% e() {
  vi
  echo "There might be some more code here, for the sake of example"
}
% e

Now we have just one process running: the main shell, and vi.  Suppose
you hit ^Z.  Then vi suspends.  The main shell is in the middle of
running e, but it's not supposed to finish doing that till vi exits.
But without special action we're now back at the top-level shell prompt
and it never will execute.

So when it detects this case the shell forks.  Now we have two processes
apart from the main shell itself: the forked shell is in the superjob, and
will eventually finish running the function.  The vi process is in the
subjob.  The superjob may have more than one process if the structure of
the code is more complicated e.g. a pipeline that needs to finish only
when the subjob is done.

Why two different jobs?  Because we have two processes separately forked
from the main shell.  When the subjob exits, the main shell will tell
the superjob to carry on, so it will print that echo --- that's why the
forked shell is the "super"job, not the other way around, and why we
show the superjob to the user rather than the subjob, because it's the
longer lived of the two.

We are having to jump through hoops because the user has been told there
is only the superjob.

On

% bg

both jobs are put into the background, though the forked shell
(superjob) will stay suspended for the time being.  In this case, the
subjob gets SIGTTOU and we now report *this* suspension (we suppress the
fact that the superjob's forked shell process is suspended as it's not
relevant to what the user thinks is going on).

On

% fg

both jobs are put back into the foreground, but again the forked shell
stays suspended.

When vi (subjob) exits, the forked shell is woken up and runs the rest
of the function.

pws

  reply	other threads:[~2018-09-26 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180926153149epcas3p1a817e8295570aa23ef107f7ecb95f980@epcas3p1.samsung.com>
2018-09-26 15:31 ` Daniel Shahaf
2018-09-26 15:50   ` Peter Stephenson [this message]
2018-09-26 17:42     ` Bart Schaefer
2018-09-26 17:52       ` Bart Schaefer
2018-09-27 15:51       ` [PATCH] Start documenting jobs.c, in particular superjobs Daniel Shahaf
2018-09-28 15:06       ` What's a superjob? Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20180926155055eucas1p2a9eeba9267adcb603fbd609e47780010~X-fvU7i_h1255912559eucas1p2q@eucas1p2.samsung.com' \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).