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

Re: Functions that start Jobs



Vincent Lefevre wrote:

> On 29 Jun, Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> 
> > Because no other shell can do this:
> 
> >   % f() { sleep 10; echo foo }
> >   % f
> >   ^Z
> >   zsh: 4022 suspended  f
> >   % fg
> >   [1]  + continued  f
> >   [ time passes... ]
> >   foo
> 
> I have 2 questions:
> 
> 1) Is the function executed in the current shell? I don't understand
> what happens exactly.

It gets wrapped into a sub-shell, i.e. you have to accept the same
consequences as if you had started it in the background from the
beginning -- it can't influence the main shell anymore (setting
parameters and things like that).

> What happens if Ctrl-Z is typed while a builtin
> is being executed?

(Very good. ;-) That won't work because we need something to find out
that something got suspended.  Some time ago we were discussing if it
was possible to make this work, too.  I don't remember exactly, but
nothing came of it.

> 2) I tried this example (with 100 instead of 10, to have more time),
> and after I typed fg, the sleep ends immediately (i.e., no time
> passes). I have the same behaviour on two machines under Linux
> (Linux/x86 and Linux/ppc). Is this normal?

It depends on how your `sleep' is written.  Some versions just put
themselves to sleep and almost any signal makes them continue (i.e.:
finish).  On other Unices (for example, this Tru64 here), `sleep' takes
its job a bit more serious and doesn't exit immediately after it gets a
SIGCONT.


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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