windows code to detect if a process is still alive

John Arbash Meinel john at arbash-meinel.com
Sat Apr 16 17:47:56 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 4/15/2011 10:20 PM, Marius Kruger wrote:
> On 14 April 2011 03:26, Martin Pool <mbp at canonical.com> wrote:
>> 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?
> 
> The h2 database has an interesting way of doing this, but it needs a
> poller thread
> which may be too much overhead for our purposes.
> (It is written in java)
> 
> http://h2database.com/html/advanced.html#file_locking_protocols
> --
> File Locking Method 'File'
> 
> The default method for database file locking is the 'File Method'. The
> algorithm is:
> 
> If the lock file does not exist, it is created (using the atomic
> operation File.createNewFile). Then, the process waits a little bit
> (20 ms) and checks the file again. If the file was changed during this
> time, the operation is aborted. This protects against a race condition
> when one process deletes the lock file just after another one create
> it, and a third process creates the file again. It does not occur if
> there are only two writers.

It is an interesting method, but it doesn't work from remote. Which is
why we settled on the 'renamed directory' to be the standard method of
taking a lock. As it works over sftp, ftp, nfs, etc. Anything else just
isn't very reliable between different machines. We do use OS locks for
working trees, and we *really* wish we didn't. Because we run into
problems time and again (mostly with remote mounted filesystems that
don't really work like local filesystems).

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2p1kwACgkQJdeBCYSNAANJrwCgvkIZShzz8e5+dk02dOX4ggHz
tPMAoMSYZcsWCybeCa6ZoPrqbvJ07vM5
=sinc
-----END PGP SIGNATURE-----



More information about the bazaar mailing list