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@mielke.cc / markm@ncf.ca / markm@nortel.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
bindthem...
http://mark.mielke.cc/