zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups
Date: Mon, 16 Apr 2018 22:39:10 -0700	[thread overview]
Message-ID: <180416223910.ZM32002@torch.brasslantern.com> (raw)
In-Reply-To: <20180415185804.GB12549@chaz.gmail.com>

On Apr 15,  7:58pm, Stephane Chazelas wrote:
}
} > > echo $(sleep 10) & echo started
} > >
} > > Only outputs "started" after 10 seconds.
} > 
} > I would say that's actually correct. $(sleep 10) is *not* a
} > background job, it's output has to be collected
} 
} But it could do that collection in the child process like all
} other shells do.

Hmm.  At first I was going to assert that this would require a lot
of changes to order of operations in exec.c, but then I noticed
this:

% time echo $(sleep 5; echo finished) & echo started
[1] 31864
started
% finished

[1]  + done       time echo $(sleep 5; echo finished)
% 

The builtin "time" (keyword really) does not time other builtins,
because they don't fork.  So it's a silent no-op in this example,
which might be an issue all its own.  However, it still introduces
an extra bit of wordcode.

What it comes down to is that "time", being a keyword, is found at
exec.c:3077 to have no "args" list, so prefork() is not invoked.
Instead the rest of the expression is in the Estate.  The whole
thing gets backgrounded and then exectime() unpacks the state and
re-calls execpline()

When "time" is not there [or has been stepped over via exectime()],
prefork() is immediately called and the substitution is waited for.

So if, when we determine that "&" is the command separator, we could
treat the command in the way the "time" prefix does, this would all
work out without mangling execcmd_exec() and prefork().

However, there are some other unique zsh-isms that would be altered
by this.  For example:

% echo ${foo::=bar} & echo $foo
[1] 31940
bar
% bar

[1]  + done       echo ${foo::=bar}
% unset foo
% time echo ${foo::=bar} & echo $foo
[1] 31943

% bar

[1]  + done       time echo ${foo::=bar}
% 

Note the assignment "sticks" in the current shell in the first case,
because it happens before the fork, but is lost in the second case.
Perhaps the former is a bug as well.


  reply	other threads:[~2018-04-17  5:39 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23 16:16 Stephane Chazelas
2018-03-23 23:36 ` Bart Schaefer
2018-03-24  5:19   ` Bart Schaefer
2018-03-24  8:05     ` Joey Pabalinas
2018-03-24 17:34       ` Stephane Chazelas
2018-03-24 22:23         ` Bart Schaefer
2018-03-25  7:00           ` Stephane Chazelas
2018-03-25  8:26             ` Stephane Chazelas
2018-03-25  7:48           ` Stephane Chazelas
2018-03-25 18:09             ` Stephane Chazelas
2018-03-27 10:17         ` Stephane Chazelas
2018-03-24 22:09       ` Bart Schaefer
2018-04-10 11:45         ` Peter Stephenson
2018-04-10 13:59           ` Peter Stephenson
2018-04-11 22:10             ` Bart Schaefer
2018-04-12 16:23               ` Peter Stephenson
2018-04-15 16:23                 ` Stephane Chazelas
2018-04-15 17:38                   ` Bart Schaefer
2018-04-15 18:58                     ` Stephane Chazelas
2018-04-17  5:39                       ` Bart Schaefer [this message]
2018-04-17  9:19                         ` Peter Stephenson
2018-04-17 16:09                           ` Bart Schaefer
2018-04-17 16:27                             ` Bart Schaefer
2018-04-17 16:35                             ` Peter Stephenson
2018-04-17 17:52                               ` Bart Schaefer
2018-04-19  9:40                                 ` Peter Stephenson
2018-04-20  9:28                                   ` Forking earlier for background code Peter Stephenson
2018-04-20 10:01                                     ` Peter Stephenson
2018-04-20 12:54                                       ` Vin Shelton
     [not found]                                         ` <CGME20180420132008eucas1p1c297624e870975cd892c74254970faab@eucas1p1.samsung.com>
2018-04-20 13:20                                           ` Peter Stephenson
2018-04-20 16:01                                             ` Vin Shelton
2018-04-23  8:29                                     ` Peter Stephenson
2018-05-01  9:23                                       ` Peter Stephenson
     [not found]                                   ` <F3A62E38-24E2-4A62-8E19-F54C9B81E9E5@kba.biglobe.ne.jp>
2018-04-23 13:52                                     ` "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups Peter Stephenson
2018-04-23 14:03                                       ` Peter Stephenson
     [not found]                                         ` <CGME20180423140859eucas1p2591bf1422614209979d4890383268c37@eucas1p2.samsung.com>
2018-04-23 14:08                                           ` Peter Stephenson
2018-04-23 15:29                                         ` Jun T.
2018-04-18  6:29                           ` Stephane Chazelas
2018-04-18 16:33                             ` Bart Schaefer
2018-04-10  9:53   ` Peter Stephenson
2018-03-25  7:38 ` Stephane Chazelas

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=180416223910.ZM32002@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).