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

Re: "echo | ps -j $(:) | cat | cat | cat" runs components in different process groups



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.



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