From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1348 invoked by alias); 5 Jan 2018 23:21:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42234 Received: (qmail 16146 invoked by uid 1010); 5 Jan 2018 23:21:57 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr0-f177.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.128.177):SA:0(-1.9/5.0):. Processed in 0.524051 secs); 05 Jan 2018 23:21:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yUNpW1oYdMDyBzyZS2rMBX/ZWxRf8k78GIN2Qg6Rshk=; b=moXlfwLWlc+7hxd9CZdVopemB40GNP4zPUM9u/eMvjXt/1pbQtL2kLfw+piXmqTmJp WvAGn3DlZgMk3LgODx+uJ6PTOutE0FxNUKFYu09wjHLuQbWHiVhLc1LTh8RGIdo+FniD o5CdJgG0M7Czxcg2hPVQpweH+Kmo/Lc5XUfuH+zxPoK1cC7wBute43vmdry0Vg09NGif AewsJLx+vZxKmgMVv5oVBFHdhlHLaNghV1ZS2xQCc8bSFKky7Jbq4bpRUo140Q7jV47p 6LwTfAaJPqgT4Ida6Z7ZS4XKjYISGFjwBr40Vq0VYCIvfAn/V0evfIHW2UTrC6RTb2fJ ANZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=yUNpW1oYdMDyBzyZS2rMBX/ZWxRf8k78GIN2Qg6Rshk=; b=MO/aKOV5O48p9kE7ag589ZoaNxH5SFv8jxd3y1/iYKbnVAf3ezb9K/OzZK/Z9xhMOe dcJH8jUqQ8ieAyVIbWo0Ptu2Qj99lxMAQttHrxgF/ERKTL6iz9OQ7P/QavStG24nt6p2 qxQz4BbkWM6ASJ9ur57XnZuJcPNtksEX/ye2aCRl6K7qXNAYUIxMYpEbl/ARL50wHC4Z 3vvesI2DA3vJKeUckPM+MqCPD831motCA6BV2qs75pAQOT0fhC0JpFg1ty7TgGQhriWs DmzDG/yL6T9/JhIEvbd3ROu4BCzEYZJhiDRJXWCvfO+0XB5aPV2U/wP6LNxU1WCB6RuU aehQ== X-Gm-Message-State: AKGB3mJDb89buqViblmcm1oJbZmdSdGr/6JH3w4Xu8G29s7uAxBE5rvz hz3FdB4nOUA5qMGZ5GOxGSqDfw== X-Google-Smtp-Source: ACJfBosOjha2rop1s6SSySdIftEUJ1ap0q5NEWJoNQs9eIVYlQpXaJA41tWyFVw9/4pjeQk+l9DBkA== X-Received: by 10.223.165.84 with SMTP id j20mr4042177wrb.278.1515194512495; Fri, 05 Jan 2018 15:21:52 -0800 (PST) Date: Fri, 5 Jan 2018 23:21:50 +0000 From: Stephane Chazelas To: Zsh hackers list Subject: Re: kill %jobspec tries to kill dead processes Message-ID: <20180105232150.GA16579@chaz.gmail.com> Mail-Followup-To: Zsh hackers list References: <20180105124602.GB16078@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180105124602.GB16078@chaz.gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) 2018-01-05 12:46:02 +0000, Stephane Chazelas: [...] > sleep 1 | sleep 3 & sleep 2 > kill %"sleep 1" > > kill still tries to kill the process that was running sleep 1 > even though the shell knows it has died: [...] I beleive the patch below should do it. I added an unrelated comment about the "sig != 0". I guess we could skip the killing altogether for sig == 0, but I left it in on the basis of "who are we do deny the user's request even if it's pointless". diff --git a/Src/signals.c b/Src/signals.c index 94f379e..e06fc05 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -779,8 +779,17 @@ killjb(Job jn, int sig) return killpg(jn->gleader, sig); } for (pn = jn->procs; pn; pn = pn->next) - if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0) - return -1; + /* + * Do not kill this job's process if it's already dead as its + * pid could have been reused by the system. + */ + if (pn->status == SP_RUNNING || WIFSTOPPED(pn->status)) + /* + * kill -0 on a job is pointless. We still call kill() for each process + * in case the user cares about it but we ignore its outcome. + */ + if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0) + return -1; return err; }