From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joan Karadimov Newsgroups: gmane.emacs.bugs Subject: bug#15983: 24.3; Emacs Not Killing Child Process Date: Thu, 19 Dec 2013 17:44:37 +0200 Message-ID: References: <87zjop3fet.fsf@sjm.io> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=047d7bb0437408573c04ede50a5c X-Trace: ger.gmane.org 1387472004 16137 80.91.229.3 (19 Dec 2013 16:53:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Dec 2013 16:53:24 +0000 (UTC) Cc: sjm@sjm.io, Bozhidar Batsov To: 15983@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 19 17:53:28 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 1Vtgqk-0007rx-4D for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2013 17:53:26 +0100 Original-Received: from localhost ([::1]:45225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vtgqj-0002ew-PS for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Dec 2013 11:53:25 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtgqR-0002NB-Et for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 11:53:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtgqM-0000gP-BX for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 11:53:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtgqM-0000gI-7i for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 11:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VtgqL-0003c9-OU for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 11:53:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87zjop3fet.fsf@sjm.io> Resent-From: Joan Karadimov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Dec 2013 16:53:01 +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: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.138747196213859 (code B ref -1); Thu, 19 Dec 2013 16:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Dec 2013 16:52:42 +0000 Original-Received: from localhost ([127.0.0.1]:58833 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vtgq2-0003bS-6t for submit@debbugs.gnu.org; Thu, 19 Dec 2013 11:52:42 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52839) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VtfmH-0001bl-AH for submit@debbugs.gnu.org; Thu, 19 Dec 2013 10:44:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtfmF-0002L8-Jl for submit@debbugs.gnu.org; Thu, 19 Dec 2013 10:44:44 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfmF-0002L0-GV for submit@debbugs.gnu.org; Thu, 19 Dec 2013 10:44:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfmD-00076Z-Ta for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:44:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtfmC-0002KP-M2 for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2013 10:44:41 -0500 Original-Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:48970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtfmC-0002K7-9O; Thu, 19 Dec 2013 10:44:40 -0500 Original-Received: by mail-wi0-f169.google.com with SMTP id hn6so6743611wib.4 for ; Thu, 19 Dec 2013 07:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=YbIHSZpDCeZ1kSSOjpRKf3lP0n/arVwwPtecrGNReh4=; b=IstxtwVkVU3+vXE27MIQ+COItUFDaft4sMF3jThbJ20d4VB1skTIQtD1C7O2BsLi4M 5RRtljshMKTFIs3E+8jmPYJx+1GzXIcZfXj/ZcIuKro0XKdo2YwMJ2BCn/WvHNLfKctV 4pM9OpChAgtsYJ/yHoDm7CaCcBeXdJ4pVYf07A5vv3HlfPi8Zhv3pV1Rms1PyK0gxwa2 AcNDUBmKX0YJiXea29cDQDa0ugg6hMkYpXb+wqG1WDBEC+zOHs+pvxnvvXz5aGp1+TfU nh/AgubTFxc8p89kcKO0XXPUf+XhOB8nYDAjdooDuU/tQa9SghaslLEpWQSlRd+xWLWV Niww== X-Received: by 10.194.189.132 with SMTP id gi4mr2044253wjc.5.1387467878428; Thu, 19 Dec 2013 07:44:38 -0800 (PST) Original-Received: by 10.216.127.68 with HTTP; Thu, 19 Dec 2013 07:44:37 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Mailman-Approved-At: Thu, 19 Dec 2013 11:52:40 -0500 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:82227 Archived-At: --047d7bb0437408573c04ede50a5c Content-Type: multipart/alternative; boundary=047d7bb0437408573804ede50a5a --047d7bb0437408573804ede50a5a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > Emacs on Windows can only monitor and kill its immediate subprocesses, > it cannot monitor, let alone kill, any of their descendant processes,> be= cause it has no idea about them. And the OS doesn't automatically> kill al= l the processes in the subprocess tree, and there's no way to> send a signa= l to them all, as on Posix platforms. If killing the> immediate child proc= ess doesn't cause some of its children to exit or> abort, then those grandc= hildren 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. --047d7bb0437408573804ede50a5a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
> 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 grandchildr=
en 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 th=
at 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 mad=
e for each descendant process. This can be reduced to a total 3 calls (rega=
rdless of the child process count)
I'll fix thes= e (and any other issues) if this fix is of any interest.

--047d7bb0437408573804ede50a5a-- --047d7bb0437408573c04ede50a5c Content-Type: application/octet-stream; name=win32-kill-children Content-Disposition: attachment; filename=win32-kill-children Content-Transfer-Encoding: base64 X-Attachment-Id: f_hpe4lmrl0 ZGlmZiAtLWdpdCBzcmMvdzMycHJvYy5jIHNyYy93MzJwcm9jLmMKaW5kZXggMmI1ODNlZi4uMGI4 MmJhMyAxMDA2NDQKLS0tIHNyYy93MzJwcm9jLmMKKysrIHNyYy93MzJwcm9jLmMKQEAgLTQzLDYg KzQzLDcgQEAgYWxvbmcgd2l0aCBHTlUgRW1hY3MuICBJZiBub3QsIHNlZSA8aHR0cDovL3d3dy5n bnUub3JnL2xpY2Vuc2VzLz4uICAqLwogI3VuZGVmIGtpbGwKIAogI2luY2x1ZGUgPHdpbmRvd3Mu aD4KKyNpbmNsdWRlIDx0bGhlbHAzMi5oPgogI2lmZGVmIF9fR05VQ19fCiAvKiBUaGlzIGRlZmlu aXRpb24gaXMgbWlzc2luZyBmcm9tIG1pbmd3MzIgaGVhZGVycy4gKi8KIGV4dGVybiBCT09MIFdJ TkFQSSBJc1ZhbGlkTG9jYWxlIChMQ0lELCBEV09SRCk7CkBAIC0yMjcwLDE5ICsyMjcxLDE0IEBA IGZpbmRfY2hpbGRfY29uc29sZSAoSFdORCBod25kLCBMUEFSQU0gYXJnKQogICByZXR1cm4gVFJV RTsKIH0KIAotLyogRW11bGF0ZSAna2lsbCcsIGJ1dCBvbmx5IGZvciBvdGhlciBwcm9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