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, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28612 invoked from network); 26 Mar 2022 18:11:36 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 26 Mar 2022 18:11:36 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648318296; b=fCz68/cu88hXjivC1lavBc52/V5Y8tJ0kMyhmOJB6WYZBEGs+P4eKLEDKCOaZKJqnIQc/m4Sjm BAxE2pMlkRsX4/F3cXT+Ltyj2COoXROYuoZm/HoGgdZrSULhHXaKLtbwfyN+4g4iZPT6o0vizv Z6G0kVMX5qBRqrwAIogUdW6iOAA+ZYgjpmGWcZciuvFqY4NbD2vnK8ES4+1uzQVaaki9VzWM1x OhOxQb7uJrnMHPDwprpafW+8Wp7E27FQfhQVwdXXIBlL0WShkUiYfrxF30aB8wphGdxzJkpVgW kn/PdfvEH2cqGG4B92jQT37diZRx034bDSqNKei0ReWHzQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (granite.fifsource.com) smtp.remote-ip=173.255.216.206; dmarc=none header.from=fifi.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1648318296; bh=6wPQqUN2x/QRWS7yZJb7LNQWE2yJswJRxLXVQV9kqmU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Content-Type: References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:DKIM-Signature; b=miQ/WjhKEP0DYv/Dlznghhzk+lWDwHL779W4g84n7uaxA7CA7gS3w8z/0mepzkWfT8itCR9Lov /Y5FMjkZf4VPZ7NwsYaxpsyJHTrALAkluHSZBHGdbXPcovt/EZm0jjwLRVHxQkbzyDuLeoyT6L ZQ536D16bCuOYPfr5eYJT2lb2TOOpRcTlie+1RFuJCSDDqxo5ZGfxopCP+PvkwlUu4ZmjnDeTh nVP76lCbXNtxI4lQnqCtzJTOwEvr+i9LR+fYMJTSlTZ5b1zqFTNBjO5KbtD4Y1FA5o/DnPppzA F8H/viuyZhOXsug7iXW+y5lG6wiV6DcPqCCZgCCPjXbNOA==; 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-Transfer-Encoding: MIME-Version:Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=EiH42q+jP/X/ZEa5BBgLHHf5CYmIbTIc9rCwURPhI00=; b=TfyJDF0I/vmbE21lTW8z75UhFh bgzxn1pqr/QQ5R9jXB4GtdPUsdznJZlGZc/N/AdDWyFB0gOC0jpKdcKRer+UwJ5T3lfd8tNYOhWhv jCrqyQvXY3+m+5sJC9588zbEH5uQc5HdPeatqpHoOYvuIKinFJO/6uey0dIuYapgNnNGKy21LOoke Hxpw28298DEfpyXXGxJsWuRE5hcGbUr36H5x6cVr7J2o7FkKK/Oa32QG3zLjCiOUTyFxKxacFyRVM 1tt2320/CQQLIUbZXdUXCODK1R4bS9wSqCNDoD59AcUpzhGKR97xRsZfhu3akmt+wFdDnNwEaDhbm Qvu33/jw==; Received: from authenticated user by zero.zsh.org with local id 1nYAsx-000GRU-QE; Sat, 26 Mar 2022 18:11:35 +0000 Authentication-Results: zsh.org; iprev=pass (granite.fifsource.com) smtp.remote-ip=173.255.216.206; dmarc=none header.from=fifi.org; arc=none Received: from granite.fifsource.com ([173.255.216.206]:43304) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1nYAs3-000Fgz-Ol; Sat, 26 Mar 2022 18:10:40 +0000 Received: from ceramic.fifi.org (107-142-44-66.lightspeed.sntcca.sbcglobal.net [107.142.44.66]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by granite.fifsource.com (Postfix) with ESMTPSA id B1B904076; Sat, 26 Mar 2022 11:10:37 -0700 (PDT) Message-ID: <36966db7bf519a888d7daca39fdd39f1e39b8511.camel@fifi.org> Subject: Re: Parallel processing From: Philippe Troin To: Bart Schaefer , Perry Smith Cc: Zsh Users Date: Sat, 26 Mar 2022 11:10:37 -0700 In-Reply-To: References: <1E0E1226-E3E8-40AD-87CD-93A602B1B08B@easesoftware.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 27626 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: On Fri, 2022-03-25 at 11:27 -0700, Bart Schaefer wrote: > On Thu, Mar 24, 2022 at 9:34 PM Perry Smith wrote: > > > This isn't exactly what you want because it waits for all four jobs > before starting the next batch, but keeping a specific number of > children running is not straightforward with the job-management > operations available to a shell. 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. There does not seem to be a way to retrieve the exit status of a command as soon as SIGCHLD is trapped: % zsh -f % echo $ZSH_VERSION 5.8.1 % setopt monitor % trap 'x=$?; echo "CHLD args=$* exit=$x"; wait $PID ' CHLD; (sleep 1; exit 1) & PID=$!; wait; echo "wait: $?" [1] 1192215 [1] + exit 1 ( sleep 1; exit 1; ) CHLD args= exit=0 wait: pid 1192215 is not a child of this shell wait: 0 % setopt nomonitor % trap 'x=$?; echo "CHLD args=$* exit=$x"; wait $PID ' CHLD; (sleep 1; exit 1) & PID=$!; wait; echo "wait: $?" CHLD args= exit=0 wait: pid 1192528 is not a child of this shell wait: 0 % trap - SIGCHLD % TRAPCHLD() { echo "CHLD args=$*"; wait $PID }; (sleep 1; exit 1) & PID=$!; wait; echo "wait: $?" CHLD args=17 TRAPCHLD:wait: pid 1192701 is not a child of this shell wait: 0 Collecting background jobs' exit status is discussed in the manual, under the POSIX_JOBS option: In previous versions of the shell, it was necessary to enable POSIX_JOBS in order for the builtin command wait to return the status of background jobs that had already exited. This is no longer the case. Setting/unsetting POSIX_JOBS does not make any difference. Anyways, zargs is not doing a stellar job currently with collecting exit statuses from commands ran in parallel: % zsh -f % autoload zargs % zargs -n 4 -P 2 -- 1 0 -- zsh -c 'sleep $1 ; exit $1 ' -; echo $? 0 % zargs -n 4 -P 2 -- 0 1 -- zsh -c 'sleep $1 ; exit $1 ' -; echo $? 123 % zargs -n 2 -P 2 -- 1 0 -- eval '(){ sleep $1 ; return $1 }' ; echo $? 0 % zargs -n 2 -P 2 -- 0 1 -- eval '(){ sleep $1 ; return $1 }' ; echo $? 123 Phil.