windows code to detect if a process is still alive
Eli Zaretskii
eliz at gnu.org
Thu Apr 14 05:24:33 UTC 2011
> From: Martin Pool <mbp at canonical.com>
> Date: Thu, 14 Apr 2011 11:26:49 +1000
>
> For detection of stale lock files, I want to detect whether a given
> process id on the local machine still corresponds to a live process.
> On unix, kill(pid, 0) will do this. What's the best way to do this
> from inside Python on Windows?
In general, on Windows you need to get the snapshot of running
processes, then walk it to look for your process.
But you cannot be sure that a process ID will not be recycled, and
another process will not use it in the meantime. On Windows, process
IDs tend to be recycled much faster than on Unix, in my experience.
So if you want a reasonably safe way of detecting stale locks, I
suggest that you tell more about the context: what is the algorithm
for detecting stale locks, when will it run (wrt the time that the
presumably dead process was run), do we know what executable ran in
that process, etc.
More information about the bazaar
mailing list