Re: Stats collection on Windows

From: mark(at)mark(dot)mielke(dot)cc
To: Magnus Hagander <mha(at)sollentuna(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Qingqing Zhou <zhouqq(at)cs(dot)toronto(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Stats collection on Windows
Date: 2006-04-05 10:06:28
Message-ID: 20060405100628.GB10082@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 05, 2006 at 10:31:37AM +0200, Magnus Hagander wrote:
> > TerminateProcess takes a HANDLE, not a process identifier.
> Yes. You get the handle by doing OpenProcess() with PROCESS_TERMINATE
> access.
> The functions used to enumerate processes all return the process id, not
> a HANDLE.(See Process32First/Process32Next). You use the HANDLE only
> when you need to *modify* something (for example, killing it).

Enumerating processes isn't a common operationg for programs other
than 'top'. :-) But even so, one can use OpenProcess() to evaluate
that the process being referenced is actually the one you think it
is, before calling TerminateProcess(), eliminating the race.

> > Yes, they provide the "kill" primitive, but only as a
> > compatibility measure.
> They do? Where is it? Certainly not in the documented SDK that I can
> see.

I believe it is called KillProcess().

> > A "good" Windows process, should
> > maintain a HANDLE to the process, and kill the process using
> > the HANDLE. This way, there is no race. The HANDLE is also
> > how you wait for the process to terminate normally.
> A "good" Windows process would be using threads ;-)

> That's what the Windows API was written for, and that's why anything
> that deals with multiple processes working together is a lot harder than
> on Unix.

Haha. Good point. :-)

Cheers,
mark

--
mark(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada

One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...

http://mark.mielke.cc/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-04-05 10:20:49 Re: Stats collection on Windows
Previous Message mark 2006-04-05 10:03:31 Re: Stats collection on Windows