From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114696 invoked by alias); 20 Jun 2017 13:18:18 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 114292 invoked by uid 89); 20 Jun 2017 13:18:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Valentin, valentin, Otto, otto X-HELO: mail-io0-f180.google.com Received: from mail-io0-f180.google.com (HELO mail-io0-f180.google.com) (209.85.223.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Jun 2017 13:18:16 +0000 Received: by mail-io0-f180.google.com with SMTP id k93so84251532ioi.2 for ; Tue, 20 Jun 2017 06:18:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=CWd/gqKTPkNUJaHMDwfaOACMzTE/X6KW84WCosilbH4=; b=RdW6F3Feu8KJoXJd95nDhQJj89AuIEEpYxphaYVyzipigy0q57i+6K4SheXpCsr51B bkykBH6l34sdoEwTGy9yu1gGoBb4eLA1xMBPfxBvn3rzj154wuYJiuT2n/40dTDhTac+ Zz5ANIQeeBI3dn+4ro0SIRDIzEUNQ8BGpdSEpB+p/lCsjuI6ByhwrhMZY4jEdn6IxLXk +kVNb7+0hRIIK+AgzN647fPZdAqRuPP8T9oMD5/ubhwyl1tE+68F4J0n4XAOIDqdZR6e ZkskBosiUjmjIgpYVsnAS4hQF1L49Tuersvw4PH1rOSQxAKAcmjHQIrSPDyg+JwALL5r jRVA== X-Gm-Message-State: AKS2vOwAuM9PBHfsPrGbG2Yhm+OnKXWGDJBcU3IONne2ff6A78eUDK2D 3aC6CUmV65xTOGI9 X-Received: by 10.107.18.146 with SMTP id 18mr18406414ios.144.1497964694368; Tue, 20 Jun 2017 06:18:14 -0700 (PDT) Received: from [192.168.0.6] (d4-50-42-50.try.wideopenwest.com. [50.4.50.42]) by smtp.gmail.com with ESMTPSA id e31sm7768893ioi.51.2017.06.20.06.18.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 06:18:13 -0700 (PDT) Subject: Re: Killing-Process woes To: cygwin@cygwin.com References: <1497939835.2871765.1014990544.3396EEF9@webmail.messagingengine.com> From: cyg Simple Message-ID: Date: Tue, 20 Jun 2017 13:18:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <1497939835.2871765.1014990544.3396EEF9@webmail.messagingengine.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg00241.txt.bz2 On 6/20/2017 2:23 AM, Ronald Otto Valentin Fischer wrote: > I'm spawning processes in background, but have problems killing them. > Here is the setup: > Maybe review the Cygwin document at https://cygwin.com/cygwin-ug-net/kill.html would help. > My script (zsh) creates one or more processes in the background, and > waits until they are finished. I have also set up a trap for SIGINT, > with the intention that if I press Control-C, the background processes > should be killed. I have verified the setup so far, that upon Control-C, > the trap function is indeed invoked, and I have all the PIDs of the > background processes. The problem is with the actual killing, and here > is why: > > The background processes are actually (zsh-) scripts, which do some > setup (basically setting various environment variables), and then invoke > a (Cygwin-)Ruby program which does the "real work". The program is > executed by something like > > ruby myprog.rb > > (Note that this Ruby program is NOT invoked in background). > > When my SIGINT trap is entered, I can see from ps indeed the > relationship between the processes involved, for instance > > 10852 9296 6224 10536 cons3 3672028 08:05:10 > /usr/bin/ruby > 9296 6224 6224 11236 cons3 3672028 08:05:10 > /usr/bin/zsh > > The PID of my background process - the zsh wrapper - in this concrete > case is 9296, and we can see that this is the parent of the Ruby > process, 10852. The problem is that if I just kill 9296, the Ruby > process keeps running, orphaned: > > 10852 1 6224 10536 cons3 3672028 08:05:10 > /usr/bin/ruby > > I've found on Stackoverflow the suggestion to treat this as a process > group and use negative PIDs. I tried this too, but it didn't work. Here > is a similar example: > Not implemented as you found out below. But I don't know that the negative process number is in use anywhere. Are you sure it wasn't a signal number as a option to kill? > 5548 10276 5812 2376 cons3 3672028 08:20:43 > /usr/bin/ruby > 10276 5812 5812 10312 cons3 3672028 08:20:43 > /usr/bin/zsh > > If I do a > > kill -- -10276 > > I get the error message > > kill: -10276: No such process > > This happens both with the zsh-builtin kill and with /usr/bin/kill Is > there a simple way to kill the zsh process in addition to the ruby > process, or do I have to analyze the output of the ps command to > manually find the PID of the Ruby process and kill it? Perhaps use the -f --force switch might help. -- cyg Simple -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple