From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27226 invoked from network); 13 Aug 2020 18:17:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Aug 2020 18:17:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=WNZZF4cX+7yO3dtL5mzCOIk1rh28jihe+3abwUYLQ28=; b=nAop88Ui+Q0jQgMjFl3ndWE7VF HHgcj2eUFhZoZ2cqT+Hil6ogpyjL2FBHTO3VevSLTbczoJUW7bIx9s8oTLm20i1pZjSvFjiweOt08 eOmub491tLtKvugv425fAPB0B/8CwWc/k+QSAqkQdjUM1QQ2WwQZM5Rn3zUCAp3e6qMPq9Vmmgjl7 3qRtwHaNWieWzQmguIkP7ZLgtZ1D2fMIGNTSSX4LZuuMlru1Xj60tAHqjyIFKXsdqOQPB11zU+/EY Y8PN9nXNAs5DBV30/TRA6QIhmAiFeebfKL60MLw43COlqh0FBoqYLNSrRrXXenSNPXahLCWwVmXTA YKkqjtEA==; Received: from authenticated user by zero.zsh.org with local id 1k6Hma-0007rP-56; Thu, 13 Aug 2020 18:16:56 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oo1-f44.google.com) smtp.remote-ip=209.85.161.44; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256 Received: from mail-oo1-f44.google.com ([209.85.161.44]:37408) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1k6Hln-00075X-Sk; Thu, 13 Aug 2020 18:16:09 +0000 Received: by mail-oo1-f44.google.com with SMTP id p137so1405585oop.4 for ; Thu, 13 Aug 2020 11:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WNZZF4cX+7yO3dtL5mzCOIk1rh28jihe+3abwUYLQ28=; b=lWcciQNNHkOfsXnRfKFMVRn8bC7/7uE9tp2rEJdwMxWVu1/v+yjgJ46mgkDx49g/tQ HN7Jnv2k5fElBuaBGT1tKDELcdENMj0vqPIJyFetm8DUP8J4rDnfWUeNMS5aVU3oVpUn OjyV689hWFNcjo0+oq6ms//KkEe59b/ohBiSSAwuKXuBpAoAv8CyuUbxlyJBMeNea6SD a3RcQg0t4eis5E4J5tmZC8PocTAhhhfbqZKmhvlJPkjksgQpN0hCqh8kZ4n9KLc0NaOH RPJLe97U1j+JR1QgBqhXVl0amwQ4s68Mgm5LkwTXOXhb/lodPg+OXE/g7D8gq4Mr3z2D Zh3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WNZZF4cX+7yO3dtL5mzCOIk1rh28jihe+3abwUYLQ28=; b=B5ZKV1KhHLNanzbU9geTzgQyDG8glBHh/1duSff/UzbEKO/kDfs613EpbcemkRWE9H HIDfvee6K75YRjRoFpx1bxbTxPnT8GkhA40E3d2NTHFAi2X828Fn7njvRyfcR8o8kGL1 596J3qG8cnfMWI25yiV6Ep3+LSEqDSM9taLbmwo3LAj9Cv3hHwNEP2dLoAr/aHkFhQE5 SIG8Wsa7GficwpyHOavdukEDIrDHXPMLfo+ICdn88xLGahuaiM1CsKjJ2QKsM2F3qOyk aLgkpQEEtdx3H8CJePr+gJtOUYkDARYh1NntQsb2aGaeu5tmk6cq5gXceFDY4/I/n5ES vY+A== X-Gm-Message-State: AOAM5322I62mR1ecPGNn1C1L8KsIvdoP9P0XUfsSiDKiC3AoJBgQUtwS vrwiXskoZxb4LyCJwiaXe5obLn4kYE04c/Uw7oc81Q== X-Google-Smtp-Source: ABdhPJyXlmx7l2icecNPcTr876ke/Nxgqh7rp9OajJIcsQShaq6bx718HR2LG7k2tJ5pzkRu6BizUXaxLdAwkz1QnQI= X-Received: by 2002:a4a:9622:: with SMTP id q31mr5820639ooi.78.1597342565157; Thu, 13 Aug 2020 11:16:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Thu, 13 Aug 2020 11:15:53 -0700 Message-ID: Subject: Re: Weird behavior with the time command and background jobs To: Rudi C Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Zsh-Org-Should-ARC-Sign: true X-Seq: 26020 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Wed, Aug 12, 2020 at 8:34 AM Rudi C wr= ote: > > =E2=9D=AF f2() { eval "$@" & } There's no subshell inside f2. > =E2=9D=AF time (f2 sleep 3 ) > ( f2 sleep 3; ) 0.00s user 0.01s system 0% cpu 3.014 total "time" forces its command to run synchronously, so here the subshell you created at the command line waits for and reports the times of its children, which includes the sleep even though the sleep itself is in the background. > =E2=9D=AF f3() { (eval "$@" &) } You have another subshell inside f3, so the eval'd command is a child of that subshell, and a "grandchild" of the shell that runs f3. > =E2=9D=AF time (f3 sleep 3) > ( f3 sleep 3; ) 0.00s user 0.00s system 41% cpu 0.007 total So here, the subshell inside f3 is not timed and not forced to be synchronous, so it puts sleep in the background and immediately exits. The subshell created at the command line, which is calculating the times, only reports the time of the subshell inside f3, not of sleep. A process can't time its grandchildren, only its children. > Why is `f2` getting 3 seconds? It's running the job in the background, ju= st like `f3`. In fact, their interactive behavior (without the time command= ) is the same. As noted above, the time command changes the behavior of the outermost subshell. It has to do this in order to read the time statistics from the operating system.