From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: child time accounting is different from other shells
Date: Wed, 10 Sep 2014 14:02:28 -0700 [thread overview]
Message-ID: <CAH+w=7aGfsix3neCcn=MTbj4Njbe4M+6OY3HiTtr2AOJGG=d2A@mail.gmail.com> (raw)
In-Reply-To: <20140910123032.GA19213@xvii.vinc17.org>
[-- Attachment #1: Type: text/plain, Size: 1409 bytes --]
On Wed, Sep 10, 2014 at 5:30 AM, Vincent Lefevre <vincent@vinc17.net> wrote:
>
> xvii% time sh -c 'pi 500000 > /dev/null & sleep 2'
> sh -c 'pi 500000 > /dev/null & sleep 2' 1.16s user 0.02s system 58% cpu
> 2.017 total
> xvii% time zsh -c 'pi 500000 > /dev/null & sleep 2'
> zsh -c 'pi 500000 > /dev/null & sleep 2' 0.00s user 0.00s system 0% cpu
> 2.023 total
>
> Is this a bug?
No, it isn't.
Zsh does a sort of tail-call optimization: In the expression "left &
right", zsh can tell that there is no further need for job-control of
"left", so it does an implicit "exec right". Other shells fork off a new
process for "right" and wait for it.
You can see the difference if you forcibly prevent the optimization by
appending a no-op command, e.g.
schaefer[101] time zsh -c 'ps & sleep 2; :'
PID TTY TIME CMD
47681 ttys000 0:00.47 -zsh
50366 ttys000 0:00.01 zsh -c ps & sleep 2; :
50370 ttys000 0:00.00 sleep 2
zsh -c 'ps & sleep 2; :' 0.01s user 0.01s system 1% cpu 2.019 total
schaefer[102] time zsh -c 'ps & sleep 2'
PID TTY TIME CMD
47681 ttys000 0:00.48 -zsh
50372 ttys000 0:00.01 sleep 2
zsh -c 'ps & sleep 2' 0.01s user 0.01s system 1% cpu 2.018 total
You can also prevent the optimization by adding an exit trap, etc.
> Shouldn't this behavior be changed to make zsh
> consistent with the other shells?
>
I would not count on this ever happening.
next prev parent reply other threads:[~2014-09-10 21:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-10 12:30 Vincent Lefevre
2014-09-10 21:02 ` Bart Schaefer [this message]
2014-09-16 10:45 ` 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='CAH+w=7aGfsix3neCcn=MTbj4Njbe4M+6OY3HiTtr2AOJGG=d2A@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-users@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).