Re: Stats collection on Windows

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: <mark(at)mark(dot)mielke(dot)cc>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "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 08:31:37
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCEA35241@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > >> Redmond crowd should be able to figure out that
> recycling process
> > >> IDs instantly would be a stupid idea...)
> > > Can you explain more of this? IMHO, if we rely on feature
> like this,
> > > the difference is unstable-every-day vs. unstable-every-year.
> > The mere existence of the kill() primitive should bring to mind
> > reasons why it's a bad idea.
>
> CreateProcess - "The process is assigned a process
> identifier. The identifier is valid until the process
> terminates. It can be used to identify the process, or
> specified in the OpenProcess function to open a handle to the
> process. The initial thread in the process is also assigned a
> thread identifier. ..."
>
> TerminateProcess - "Terminates the specified process and all
> of its threads."
>
> 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).

> 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.

> 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.

//Magnus

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message mark 2006-04-05 10:03:31 Re: Stats collection on Windows
Previous Message Magnus Hagander 2006-04-05 08:22:55 Re: Stats collection on Windows