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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20731 invoked from network); 3 Dec 2023 21:59:01 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Dec 2023 21:59:01 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1701640741; b=kHlfo97TWBnae7dJV1A70K1TMJtDpFFhRfZSkh65V7uvIbsFZZa53wwA1QQWOjEyNBMell2Zb9 pB3HI7GNePvOHxDWVc9s2tB3Bt03VCA3DdHbKksK79dfhZraOe5Mt6jhk21JkbZPtJKPRUMSeY M+qyhEe4KcHfgI0tzWVxqx6r3Vbqu/FIz+77Owr8uAqFLnAMhzFTsZQuVVIJpcHGfO+aaQr1gI Uum6+YeqrzwH85BEJJRWylbCb91NDIqFwJLwIyExIQQLZ3m+7ncaUFENqE2cFiBj4L/PYtrJIZ jUvD4mdxbhqinSDxNhI/SCc/rFTWQU8+dH2RlCxcO5p0GQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1701640741; bh=wW2hHwCcZ/ESnh2vlMStAL5wOcFCkIgZpUJ2qB/hUAY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=WtfhryWcEUTloo/BF+rs3N+OK5Qj2rOeSRy8Kio36sF88vn9J+vtrbMtpEEWKHK69CLAcJGsWY khI3a9rSHsW1VPPlEljDyAZ67JJAnqUw6SPhyvZEFwJCqT+4oXnEUd3E51qnl+EDJ12jxz3FA+ Zi7IiNA1ndqKlJXBLhlybf0s6Oogx+uLc/vuXaY76qvhcUW+e5E8uCGsgAxd45JuR3KPYV/e8D WXQLYHW3hO2I8HFPKhccl+D4atvaaqCbi9QFdHsQOlM8gUPTsKyO14dU/rdUYRO2bLG+RyHtv4 ZwgfZtKsgfGNt5AI9TEfrb1biixf84g7ePhVnSs6ifKFuQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=mrjo8IqjS/j8QfnBs2FS3K2hPRcmKFQMc4Tm0MPfrlU=; b=HcVg8Hysng/Uj0lNfAN6iWJw9O OU6EVLJZKmAFW9zL4vS7Gq2/mitrXh/aalr6eOCcHOfLRUCRhOuiv9767mJp3aR4xzJvf6x+odZU4 Ij/rIPo/7GDpOiwplSdD3lkUsDIZ2sKyiMytqLD3l9F1fFhDXbrp3NqbmrYoe0amdLS4+Z1UJFG8L JuWbjtThe0B7FixoR+a42kVSvxdA8Rvg2xmF4Y95Jg8ZDN0ojfH2N4bt9CfFnAk8ZHLKFZX1Q73tD 157Lmc+djRDvgJeAgdBjkpmexCUn1S9MgfJpWGYvmPVCStYLlxid2HJCWhwjgedRfB7tkwBadC1KI d4lKmo+g==; Received: by zero.zsh.org with local id 1r9uUO-000JWy-Rx; Sun, 03 Dec 2023 21:59:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f50.google.com ([209.85.218.50]:53296) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1r9uTj-000Ipu-Bo; Sun, 03 Dec 2023 21:58:19 +0000 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a195a1474easo375576266b.2 for ; Sun, 03 Dec 2023 13:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1701640699; x=1702245499; darn=zsh.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mrjo8IqjS/j8QfnBs2FS3K2hPRcmKFQMc4Tm0MPfrlU=; b=FMDWESq7fn4hyfLo04y4ZW6GYaZKxvol663c60VRqyytcsXwMYrNV/p+5wwa3H5qG4 PN/SmmcSCJp0FqX9kMBaiIR8hId7yJEmy5UCWBQagz7UVqQ6Ci6zqk0k2Soa1r0d393Y HtgaPl5RP5c09OxDqugsQxnXnMvmhczGm1z8kkj1S8JeS2xbFNUtoXIMvUE375ZoHyDa gWBjHlWaMIu0ShC0np2tcripdq7BvG4FE+zbZ3/pHmyOgyej3z5Pft338KS4mZfUabHJ mIaEmzVP62S3FhBZwo3E7SiLXfh2y0wsCwrLZzV6hIYFjVW3KdZK+tYKL7Noto+faAM6 TYaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701640699; x=1702245499; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mrjo8IqjS/j8QfnBs2FS3K2hPRcmKFQMc4Tm0MPfrlU=; b=c8CnjzTjT8jtlX8f3pw1823SnnXKuft7CavylEx9p8rhWpOx0SqKrMDlfniDXVQkEU AFKLujr7Mf1wsqWUIfpysEPKUM/FnCCFHLojdKcVMy7fO0DvvZgdB3t0dcH4aZ3R6xov FUhaGIQjvEXLsRlvE8A4nUkunB/RYJjzWYWOs99MUhxjtuVyRserSQ1ZAfOUr4sPGsdt lwc+wm2DVHLjRTgXwA7lV3Sx/uCWyxPG3buX7hkrz7XezZXMAYX1Fr4MJ6zeTItzLazE bYWEINjn4IOPbcxE04lrneMkl4bf1Lyd62gkNmjaKrs2zJowxKuN1pEnB45YDNI8EI6X rXkQ== X-Gm-Message-State: AOJu0Yy5w4F8DUwAkotDpwlUlqE1JsKSm8SOqJj6AL8WyYqiFTiB/Jgt DSry/QZUwmnaSD5Tx6sfh/8Wn0vBqTC3Tg8xPEtiNa/WULn1+ShPU/8= X-Google-Smtp-Source: AGHT+IGAZLdbZxib6GzJk3lW2t71weRyUDwa4mtebNBborhmY3b3BA9X2up2jilOvOHBOdVA3XRU3jkMiVoDpba1ewI= X-Received: by 2002:a17:906:11e:b0:a18:5c94:3328 with SMTP id 30-20020a170906011e00b00a185c943328mr4085735eje.20.1701640698355; Sun, 03 Dec 2023 13:58:18 -0800 (PST) MIME-Version: 1.0 From: Bart Schaefer Date: Sun, 3 Dec 2023 13:58:07 -0800 Message-ID: Subject: Trapping SIGCHLD To: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 29360 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: Found the first part of this sitting in my drafts folder from a year and a half ago. On Sat, Mar 26, 2022 at 11:10 AM Philippe Troin wrote: > > There may be a way to achieve keeping a set number of children around, > by trapping SIGCHLD, but we would completely lose the exit status of > the command. Is it necessary to grab the exit status right away, or just to obtain it eventually? If the CHLD trap did nothing but decrement a counter every time a child exited, a new child could start right away, increment the counter, and then (possibly much) later an explicit "wait $childpid" could be done. > There does not seem to be a way to retrieve the exit > status of a command as soon as SIGCHLD is trapped It's a bit round-about, but: watchCHLD() { setopt localoptions nonotify trap 'print -p wakeup; trap - CHLD' CHLD coproc read -E read -p } waitchild () { watchCHLD wait $1 } () { sleep 20; return 23 } & waitchild $! print $? If/when the patch from workers/52365 goes in, it'll be possible to get the status of a specific PID in the CHLD trap itself. However, if multiple children exit at the same time the CHLD handler may be called only once, so some trickery with $jobstates is necessary. If this is still of interest I'll try to work out details.