zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: RE: pws-22: killing the ZSH loops problem (with PATCH)
Date: Tue, 22 Jun 1999 11:35:56 +0200 (MET DST)	[thread overview]
Message-ID: <199906220935.LAA24578@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Andrej Borsenkow"'s message of Mon, 21 Jun 1999 20:14:52 +0400


Andrej Borsenkow wrote:

> > } > } We need it only if MONITOR is set
> > } >
> > } > Not true!  MONITOR only affects handling of ^Z, not of ^C.  We need to be
> > } > able to properly interrupt such loops in any shell.
> > }
> > } Ahem ... yes. What about "only in interactive shells?"
> >
> > What about "kill -INT"?  What about a shell script that isn't interactive
> > but that's running in the foreground?
> >
> 
> The shell script running in foreground will get INT from tty because it is in
> TTY group and can do anything with it. The same, if I do kill -INT. The problem
> only ever happens with loops started as part of shells with MIONITOR option set,
> because it runs part of command (loop) in other process group as loop itself.
> That prevents it from seeing this INT.

Please remember that the program sees the INT all right. The problem
is that some programs fail to allow the shell to see that they
terminated because of a signal. With well-behaved programs the shell
shouldn't need to see the INT.

> > } If don't miss something again: we have to fork only for the loop as whole.
> >
> > That's right, but the reason we don't do this now is so that parameter
> > assignments inside the loop are visible after the loop terminates.  That
> > doesn't work in most other shells.
> 
> As I understand, the last part of pipeline runs in current shell, and Sven's
> suggestion was basically to run while ... done loop as <dummy command> | while
> ... loop. May be, I was wrong.

That's right -- only that we don't even need to use a pipe. We would
just create a (well-behaved but never ending) dummy process with it's
own pgrp and put the command from the shell construct in that
group. That way we can see the signals by looking at the dummy.

> And another way is to run commands in the process group as shell and catch INT.
> Is it even remotely possible?

It's what you get after `unsetopt MONITOR'. The problem with this is
that we would have to implement those parts of job control directly
that we get for free when we can use process groups.

> > } ... so, it seems, execution time penalty is acceptable.  After all, you
> > } don't use loops on every prompt.
> >
> > The execution time isn't as much at issue as is the process table space.
> 
> If it is needed (as I still believe) only for loops, started at PS1 when MONITOR
> is set - it hardly happens too often. And having to kill your login shell to get
> out of loop is not as nice

For every shell construct, not only loops. And you don't have to kill
the shell even now (since you can always ^Z it -- and then kill or
fg/^C).

When thinking about implementations I would certainly prefer the
solution using the dummy process because most of what should be needed 
for it is already there (the existing super/sub-job code). But we
would also need it for every shell construct in a function that is
called from the command line...

If you try that last one you'll notice that suspending such functions
does not work. Well, the function stops all right but you don't get a
job table entry for it. The patch below fixes this -- the job was
deleted on the way up the call chain.

Bye
 Sven

diff -u os/exec.c Src/exec.c
--- os/exec.c	Tue Jun 22 08:59:14 1999
+++ Src/exec.c	Tue Jun 22 11:31:51 1999
@@ -914,8 +914,10 @@
 		    jn->stat |= STAT_STOPPED | STAT_CHANGED;
 		    printjob(jn, !!isset(LONGLISTJOBS), 1);
 		}
-		else
+		else if (newjob != list_pipe_job)
 		    deletejob(jn);
+		else
+		    lastwj = -1;
 	    }
 
 	    for (; !nowait;) {

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


             reply	other threads:[~1999-06-22  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-22  9:35 Sven Wischnowsky [this message]
1999-06-22  9:45 ` Andrej Borsenkow

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=199906220935.LAA24578@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).