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 29469 invoked from network); 26 Mar 2022 22:20:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 26 Mar 2022 22:20:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648333252; b=i0WzljdVdNV3ELXTuiw5XFWv71C9K1LgCc7oCWuKjaKGd4a6tu18YM685q5jbVeuNhjMbiHWvG 2sAfkdaLANXumtZxucu+aBdAjjFrXAKLzXZuXC+WJnN7jv1oCKSrsA1ZLO9asHw0ibDoZNZ6n3 I8y+uQJPXzWVKyI3xWG7KQd9RPSsngoMp1puINLLyU7BaZbmJBrMze65iRspIo/+ovt6DcbvFu R/ooxlZJ1xnPCnhbEiu6V8ybBgvai4N3UvIHRq53WMnio+P7DsGCBvTqgUBO0NkTT0TYJx9kjc NHM+va5VYHGenqmWrukcOkOqgoprRMH8ZcMJaJupM6u0Xw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f44.google.com) smtp.remote-ip=209.85.167.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1648333252; bh=cYA99jN+4vzSa+gb1eQjXhH0vERmQLMlj+392YYrJQo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=GaysDMAEqDjJhy0o5v7LKjSKrqNlUynY1O35P+FknUaMvA6qX2AYrxIOI4AR2Lfa9QyGjRjjLL o/egWBG1hJBgy/wZ3EgntNm5XgDIdElAiiZ7C+TOiNuZplRwF1GTJBWtl+Og3OHI2NUKP2XU6M ktNrYtK5UUz1LBnFLtVggj3Qq0SNlbsGxeG8JXPm3V8kkUC5djLXYAC7/6pnuaH/PQB3TloxpE wLQw92YGmWjZBRMDWcF9ywdoCD/fqfYspmzrmYefmpnYo4Fg1PLa235uw7i+cXpo07/dQJEXWL eSmgBseVG3yq6y5yS9K9cB/bMFM3CVUKLqOKBBxUIPasAw==; 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:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kz2dPh8D7nf2yLq+VQMk3gk138GJzM397uAcGvZ89os=; b=ZuJCGBd49f6XtXG6tMhDR2tevh 7OVgiKd9Ke1QLsCs9IKZ3jMO8ojHyzXpWBd/CnI5TNSZ6fYyuT3wCSct0xnH6DG76RdID0Ey0EWsP 0UtfIhYfPSXW1cjpWsLVRy3+0oJpYko0D5pmQfpZdwotowaNJy3IXfvj/xQI/xS41PCqUVIqYOBKa Y2lFe+jU/p5RvzkiFGZmPIs4fGgKEEl9hDwyOeKUkget7U29EpDm8B+BxwJieA414KCYMNaohjjtO ET36LxdPpzrOXHuHv+66ItdR91zCpUPP5TYR9ZQ7PSgc3/Fp+CCXuqV/Bcjkz9IE4wUlJDV6PDS4w ym3n2P2w==; Received: from authenticated user by zero.zsh.org with local id 1nYEmB-000NFh-7b; Sat, 26 Mar 2022 22:20:51 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f44.google.com) smtp.remote-ip=209.85.167.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lf1-f44.google.com ([209.85.167.44]:46772) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nYEku-000MXA-VJ; Sat, 26 Mar 2022 22:19:35 +0000 Received: by mail-lf1-f44.google.com with SMTP id e16so18907678lfc.13 for ; Sat, 26 Mar 2022 15:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kz2dPh8D7nf2yLq+VQMk3gk138GJzM397uAcGvZ89os=; b=3t8J3qFyfMULUmF5a8b7RN80Ifu7c9hQnexJhN4Qolha+jORtDNAalTahsu5ade78R eBUW00CC7hgTPWroyrhtWXJlliVt3h5browC8i3jppE8Ei9kebShpQNnsFEJyF5o8DAT EINjs3h1/Ijxx4Xo2FelYQKNXzSUPCU2ur87prIdIL8VVVMeTG+40SFQgIjclSMzJOxS m05UXWsfwTuAVUPJ/cK2lOqnqUtV1UICC4RTBev7/JX2nxwI87mhQlCpLJxgwRV3IJ1s KXxhIKtGdFxWEBwJR+YFeWfACHGgYpvT6hS2qM77R+TL4O7BFH3t7pdf0TevgVpoVKFp FqzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kz2dPh8D7nf2yLq+VQMk3gk138GJzM397uAcGvZ89os=; b=nu0ohEySD86fNMtq4157og0Tzry2RYQeP0LLJ0D+BQFgnsx7yj7MVh4X2GK8CyK4Jw RHZ+1thdqHJlkwNQrBk36S7otNXz8Sn1YWjXtUM8cazvFA/8t8yatDilKkFZFENYcEoX Hyn4DESfIJc3UmD3XKRigluemp5+5IkE4MWYKId55YyhvrBPQED65lK5pIBVs0ft45F7 S24Kl+wb92MZLG5f0hs7X8alQcoxwt0zrvLxJELUPLxnVDmiVXL/TCKsr2hnllb2hNfS sjQKV0QyTEYmEi7Bbi/uprgLRPHlOha+J7Oz67EE+1nJFK68T39EbEwCUExFPfndmiYV pSKA== X-Gm-Message-State: AOAM533WsLJI/Z40EjI/zHZVB3p/k1ai0HNh0lLeJKRVvaurRQ8J3qnE p9A+D2qABwcHNrRb/VoTmo9WnSitVg1jylybRJGzdA== X-Google-Smtp-Source: ABdhPJxxSY+W43aOtBwXaEVLjoTfc1zGpZ0M4ZtqAs72sCUBmOtTYHZMCEllcy9eETEVYQSWbrUv1FG0z0M4emRFZlg= X-Received: by 2002:ac2:418c:0:b0:43e:8f98:98f0 with SMTP id z12-20020ac2418c000000b0043e8f9898f0mr13973329lfh.604.1648333171510; Sat, 26 Mar 2022 15:19:31 -0700 (PDT) MIME-Version: 1.0 References: <1E0E1226-E3E8-40AD-87CD-93A602B1B08B@easesoftware.com> <36966db7bf519a888d7daca39fdd39f1e39b8511.camel@fifi.org> In-Reply-To: <36966db7bf519a888d7daca39fdd39f1e39b8511.camel@fifi.org> From: Bart Schaefer Date: Sat, 26 Mar 2022 15:19:20 -0700 Message-ID: Subject: Re: Parallel processing To: Philippe Troin Cc: Perry Smith , Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27627 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 Sat, Mar 26, 2022 at 11:10 AM Philippe Troin wrote: > > 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. % (sleep 1; exit 13) & PID=$!; wait; wait $PID; echo "wait: $?" [1] 64029 [1] + exit 13 ( sleep 1; exit 13; ) wait: 13 The "wait" command with no arguments does not return a status for any job, it just hangs until there are no jobs left, and then returns 0. This is consistent with e.g. bash. So when the doc says "The exit status from this command is that of the job waited for" it should be more precise about what "the job" means. You have to identify in the argument list the job(s) whose status you want. > There does not seem to be a way to retrieve the exit > status of a command as soon as SIGCHLD is trapped: Indeed ... the trap handlers are called when the signal arrives (so the child process has exited) but before the job has actually been [C library level] waited-for, so the internal tables that are used to track the exit status of those children have not been updated. The job search code invoked by the "wait" builtin therefore can't find the job. > Anyways, zargs is not doing a stellar job currently with collecting > exit statuses from commands ran in parallel: # Everything has to be in a subshell just in case of backgrounding jobs, # so that we don't unintentionally "wait" for jobs of the parent shell. Hmm ... zargs uses wait ${${jobstates[(R)running:*]/#*:/}/%=*/} to wait for all the backgrounded jobs that it started. (This causes a segfault in the most recent git checkout if zargs itself is a subshell job.) However, that "wait" returns the exit status of only one of those jobs. There might be something more that could be done now, to pick up the status of the rest ... but I'm reluctant to mess with that while the segfault is unfixed. > % zargs -n 4 -P 2 -- 0 1 -- zsh -c 'sleep $1 ; exit $1 ' -; echo $? > 123 This is explained in the comments in zargs: # Like xargs, zargs exits with the following status: # 0 if it succeeds # 123 if any invocation of the command exited with status 1-125 # 124 if the command exited with status 255 # 125 if the command is killed by a signal # 126 if the command cannot be run # 127 if the command is not found # 1 if some other error occurred.