* child time accounting is different from other shells
@ 2014-09-10 12:30 Vincent Lefevre
2014-09-10 21:02 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Vincent Lefevre @ 2014-09-10 12:30 UTC (permalink / raw)
To: zsh-users
With all shells I could test except zsh,
time sh -c 'pi 500000 > /dev/null & sleep 2'
where "pi 500000 > /dev/null" lasts for less than 2 seconds
(or replace it with any command that takes CPU time less than
2 seconds), includes the time taken by this child process in
the user/system times, but not with zsh:
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? Shouldn't this behavior be changed to make zsh
consistent with the other shells?
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: child time accounting is different from other shells
2014-09-10 12:30 child time accounting is different from other shells Vincent Lefevre
@ 2014-09-10 21:02 ` Bart Schaefer
2014-09-16 10:45 ` Vincent Lefevre
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-09-10 21:02 UTC (permalink / raw)
To: Zsh Users
[-- 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: child time accounting is different from other shells
2014-09-10 21:02 ` Bart Schaefer
@ 2014-09-16 10:45 ` Vincent Lefevre
0 siblings, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2014-09-16 10:45 UTC (permalink / raw)
To: zsh-users
On 2014-09-10 14:02:28 -0700, Bart Schaefer wrote:
> You can also prevent the optimization by adding an exit trap, etc.
Actually any trap prevents the optimization.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-16 10:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10 12:30 child time accounting is different from other shells Vincent Lefevre
2014-09-10 21:02 ` Bart Schaefer
2014-09-16 10:45 ` Vincent Lefevre
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).