From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bozhidar Batsov Newsgroups: gmane.emacs.bugs Subject: bug#15983: Fw: bug#15983: 24.3; Emacs Not Killing Child Process Date: Thu, 19 Dec 2013 17:56:46 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="52b3173e_52d7b105_1c26" X-Trace: ger.gmane.org 1387468687 5695 80.91.229.3 (19 Dec 2013 15:58:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Dec 2013 15:58:07 +0000 (UTC) To: 15983@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 19 16:58:12 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VtfyQ-0002av-98 for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2013 16:57:18 +0100 Original-Received: from localhost ([::1]:44992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfyQ-0004qR-06 for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2013 10:57:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfyG-0004q5-CJ for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:57:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtfyB-0006I6-3M for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:57:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfyA-0006Hs-V8 for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:57:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VtfyA-0001yB-Hi for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Bozhidar Batsov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Dec 2013 15:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15983 X-GNU-PR-Package: emacs,w32 X-GNU-PR-Keywords: Original-Received: via spool by 15983-submit@debbugs.gnu.org id=B15983.13874686147551 (code B ref 15983); Thu, 19 Dec 2013 15:57:02 +0000 Original-Received: (at 15983) by debbugs.gnu.org; 19 Dec 2013 15:56:54 +0000 Original-Received: from localhost ([127.0.0.1]:58801 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vtfy1-0001xi-Pb for submit@debbugs.gnu.org; Thu, 19 Dec 2013 10:56:54 -0500 Original-Received: from mail-ea0-f182.google.com ([209.85.215.182]:64360) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vtfxy-0001xZ-Ty for 15983@debbugs.gnu.org; Thu, 19 Dec 2013 10:56:51 -0500 Original-Received: by mail-ea0-f182.google.com with SMTP id a15so571321eae.41 for <15983@debbugs.gnu.org>; Thu, 19 Dec 2013 07:56:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :content-type; bh=0KDGylb7/hRgBP/y03MUoiVBHKOdnq6UVpnkx+TC+pY=; b=R5eatVvBSj9/tm3m19wbKbLbhguoRbSPPfPU4UkfU0KOFzA7+E9hHzxGRN6IbG5Q9P OhN4kVmDYkkYwIZnAUQOJGFwmsJGZcq+c3i29L4O5rppSCXOrqqZ7rPpH5DdFMP05Eku TnbJVYhisAwkEy3/JwgLswCx9PqO0KJLkyMHimkGJmbHaToujyYzVPjMpWDB35od1z9L +/lGhxROB8xXx4yEokWgSVw7FduDZuVI+9INynMuY+D73cvjKwDTv6rrX+v/lZE5LTve 3J/pNlax8uZT/5w4wX0e477gvTOgZzAbsa7Ida3DQMTdPRCg58G+uVDW+TXmRkz9LmBU cVpw== X-Received: by 10.14.7.2 with SMTP id 2mr551016eeo.16.1387468609817; Thu, 19 Dec 2013 07:56:49 -0800 (PST) Original-Received: from [192.168.1.28] ([95.87.231.111]) by mx.google.com with ESMTPSA id n1sm10434972eep.20.2013.12.19.07.56.48 for <15983@debbugs.gnu.org> (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Dec 2013 07:56:48 -0800 (PST) In-Reply-To: X-Mailer: sparrow 1.6.4 (build 1178) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:82223 Archived-At: --52b3173e_52d7b105_1c26 Content-Type: multipart/alternative; boundary="52b3173e_dcdf8f6_1c26" --52b3173e_dcdf8f6_1c26 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Forwarded message: > From: Joan Karadimov > To: bug-gnu-emacs@gnu.org > Cc: sjm@sjm.io, eliz@gnu.org, Bozhidar Batsov > Date: Thursday, December 19, 2013 at 5:44:37 PM > Subject: bug#15983: 24.3; Emacs Not Killing Child Process > > > Emacs on Windows can only monitor and kill its immediate subprocesses, > it cannot monitor, let alone kill, any of their descendant processes, > because it has no idea about them. And the OS doesn't automatically > kill all the processes in the subprocess tree, and there's no way to > send a signal to them all, as on Posix platforms. If killing the > immediate child process doesn't cause some of its children to exit or > abort, then those grandchildren will be left orphaned. Windows NT does have the concept of parent processes, but an API call wasn't exposed in win32 until XP. I wrote a small patch that uses that and kills all child processes (as long as pid<0). I did some sanity testing and it works. > There are a few things that this patch leaves unaddressed: - there is no error handling - there is no OS detection - this will get ugly on Windows 9x and NT4/5.0 - performance: 3 API calls are made for each descendant process. This can be reduced to a total 3 calls (regardless of the child process count) > > I'll fix these (and any other issues) if this fix is of any interest. > --52b3173e_dcdf8f6_1c26 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
=46or= warded message:
=20 =46rom: Joan Karadimov <joan.karadimov=40= gmail.com>
=20 =20 =20 To: bug-gnu-emacs=40gnu.org
=20 =20 Cc: sjm=40sjm.io, eliz=40gnu.org, Bozhidar= Batsov <bozhidar.batsov=40gmail.com>
=20 Date: Thursday, December 19, 2013 at 5:44:= 37 PM
Subject: bug=2315983: 24.3; Emacs Not Kill= ing Child Process
=20
=20
> Emacs on Windows can only monitor and kill it=
s immediate subprocesses,
> it cannot monitor, let alone kill, any of their descendant processes=
,
> because it has no idea =
about them.  And the OS doesn't automatically
> kill all the processes =
in the subprocess tree, and there's no way to
> send a signal to them a=
ll, as on Posix platforms.  If killing the
> immediate child process=
 doesn't cause some of its children to exit or
> abort, then those grand=
children will be left orphaned.

Windows NT does have the concept of parent proce=
sses, but an API call wasn't exposed in win32 until XP. I wrote a small p=
atch that uses that and kills all child processes (as long as pid<0). =
I did some sanity testing and it works.
There are a f=
ew things that this patch leaves unaddressed:
-=
 there is no error handling
- there is no OS detection - this will get ugly on Windows 9x and NT4/5.0=

- performance: 3 API calls a=
re made for each descendant process. This can be reduced to a total 3 cal=
ls (regardless of the child process count)
I'll fi= x these (and any other issues) if this fix is of any interest.

=20

--52b3173e_dcdf8f6_1c26-- --52b3173e_52d7b105_1c26 Content-Type: application/OCTET-STREAM Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="win32-kill-children" ZGlmZiAtLWdpdCBzcmMvdzMycHJvYy5jIHNyYy93MzJwcm9jLmMKaW5kZXggMmI1ODNlZi4uMGI4 MmJhMyAxMDA2NDQKLS0tIHNyYy93MzJwcm9jLmMKKysrIHNyYy93MzJwcm9jLmMKQEAgLTQzLDYg KzQzLDcgQEAgYWxvbmcgd2l0aCBHTlUgRW1hY3MuICBJZiBub3QsIHNlZSA8aHR0cDovL3d3dy5n bnUub3JnL2xpY2Vuc2VzLz4uICAqLwogI3VuZGVmIGtpbGwKIAogI2luY2x1ZGUgPHdpbmRvd3Mu aD4KKyNpbmNsdWRlIDx0bGhlbHAzMi5oPgogI2lmZGVmIF9fR05VQ19fCiAvKiBUaGlzIGRlZmlu aXRpb24gaXMgbWlzc2luZyBmcm9tIG1pbmd3MzIgaGVhZGVycy4gKi8KIGV4dGVybiBCT09MIFdJ TkFQSSBJc1ZhbGlkTG9jYWxlIChMQ0lELCBEV09SRCk7CkBAIC0yMjcwLDE5ICsyMjcxLDE0IEBA IGZpbmRfY2hpbGRfY29uc29sZSAoSFdORCBod25kLCBMUEFSQU0gYXJnKQogICByZXR1cm4gVFJV RTsKIH0KIAotLyogRW11bGF0ZSAna2lsbCcsIGJ1dCBvbmx5IGZvciBvdGhlciBwcm9jZXNzZXMu ICAqLwotaW50Ci1zeXNfa2lsbCAocGlkX3QgcGlkLCBpbnQgc2lnKQorc3RhdGljIGludAora2ls bF9wcm9jZXNzIChwaWRfdCBwaWQsIGludCBzaWcpCiB7CiAgIGNoaWxkX3Byb2Nlc3MgKmNwOwog ICBIQU5ETEUgcHJvY19oYW5kOwogICBpbnQgbmVlZF90b19mcmVlID0gMDsKICAgaW50IHJjID0g MDsKIAotICAvKiBFYWNoIHByb2Nlc3MgaXMgaW4gaXRzIG93biBwcm9jZXNzIGdyb3VwLiAgKi8K LSAgaWYgKHBpZCA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