all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Joan Karadimov <joan.karadimov@gmail.com>
Cc: sjm@sjm.io, bozhidar.batsov@gmail.com, 15983@debbugs.gnu.org
Subject: bug#15983: 24.3; Emacs Not Killing Child Process
Date: Thu, 19 Dec 2013 19:24:34 +0200	[thread overview]
Message-ID: <83ob4cbvot.fsf@gnu.org> (raw)
In-Reply-To: <CAGVACNVfa8bvqHDOavzUzb6mGCxRHPzu2Pbv4Yi-76Ca+B_Rcw@mail.gmail.com>

> Date: Thu, 19 Dec 2013 17:44:37 +0200
> From: Joan Karadimov <joan.karadimov@gmail.com>
> Cc: sjm@sjm.io, eliz@gnu.org, Bozhidar Batsov <bozhidar.batsov@gmail.com>
> 
> > 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.

Thanks, but I don't think we can use this code safely: there's a race
condition here between the time the snapshot is taken and the time the
process in the snapshot is killed.  During this time window, however
small, a process ID can be reused for a completely different process.
Killing an unrelated process is a no-no.

Moreover, AFAIU the code takes multiple independent snapshots of the
process tree, which are not guaranteed to be consistent between them
on a live system which resuses process IDs as fast as Windows does.

The only safe way on Windows to make sure a process ID is not reused
is to keep a handle open on the process.  But such a strategy would
require some kind of notification to Emacs from its subprocesses when
they launch their subprocesses.  If you (or someone else) know how to
set this up, we could indeed resolve this problem.  Otherwise, I'm
afraid we will need to live with this some more.

> - there is no OS detection - this will get ugly on Windows 9x and
> NT4/5.0

This is not a problem: we already call these functions in Emacs, and
have the necessary machinery to detect whether the API is available.
Take a look at create_toolhelp32_snapshot in w32.c, and its callers.

> - 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 doubt that this should count as a problem, since we are talking
about extreme cases anyway.

The only real problem is the one I mention above.

Thanks for working on this.





  parent reply	other threads:[~2013-12-19 17:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 17:47 bug#15983: 24.3; Emacs Not Killing Child Process sjm
2013-11-27 21:02 ` Eli Zaretskii
2013-12-19 15:44 ` Joan Karadimov
2013-12-19 15:56   ` bug#15983: Fw: " Bozhidar Batsov
2013-12-19 17:24   ` Eli Zaretskii [this message]
2013-12-20 22:28     ` Joan Karadimov
2013-12-21  8:15       ` Eli Zaretskii
2013-12-21 16:22         ` Joan Karadimov
2013-12-21 18:38           ` Eli Zaretskii
2013-12-22  2:03             ` Joan Karadimov
2013-12-22  3:53               ` Eli Zaretskii
2013-12-23 16:02                 ` Joan Karadimov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83ob4cbvot.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=15983@debbugs.gnu.org \
    --cc=bozhidar.batsov@gmail.com \
    --cc=joan.karadimov@gmail.com \
    --cc=sjm@sjm.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.