From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12845 invoked by alias); 10 Sep 2014 21:02:36 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19061 Received: (qmail 7875 invoked from network); 10 Sep 2014 21:02:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=6KvgBwt8fBfx5n8dTyapxnS4/Ln4JEnfNiVOJGnUlGc=; b=MPh2xlu1f6cD3yXkaBzat3/gBupN97Ny6Q86AmEFBWSDus2f5fkjppQa7wJ7qOOySx PdETnFEzqW2NRybZV9T3UBwoB1qAp1fgnUaoLj36qM4pGr/tTLmdwTrNz904B5NfCXDO gzSoF0F15VUWf8N5P+wL5NtprlagWq9+/PPljcACvajRFoEgkhDmzC9ykLGxRwPSPVDX +w3Tk33XPHIl3gFpPndTvCNFUgavirEOt4pkyDYkx8JkkIvKryusIyKYgpPmeUdjtsNf dBLXIKd/pNbzTZaNg5dbWDNXiNs/M7t0cRdB5WoUhVGAgType8DMANd+BrBgs6JifmNC XGYw== X-Gm-Message-State: ALoCoQnY4xoJiguspG8k/T7wLtlSDH8NyfCTcSnUYrEbDtJptGyG1hwo8WFJ1aY+ArMLbnjiMhw0 MIME-Version: 1.0 X-Received: by 10.113.3.139 with SMTP id bw11mr4640254lbd.98.1410382948442; Wed, 10 Sep 2014 14:02:28 -0700 (PDT) In-Reply-To: <20140910123032.GA19213@xvii.vinc17.org> References: <20140910123032.GA19213@xvii.vinc17.org> Date: Wed, 10 Sep 2014 14:02:28 -0700 Message-ID: Subject: Re: child time accounting is different from other shells From: Bart Schaefer To: Zsh Users Content-Type: multipart/alternative; boundary=001a11349454a3bba20502bc5ed4 --001a11349454a3bba20502bc5ed4 Content-Type: text/plain; charset=UTF-8 On Wed, Sep 10, 2014 at 5:30 AM, Vincent Lefevre 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. --001a11349454a3bba20502bc5ed4--