in reply to Killing a process on Windows (Win32::Process question)
The remarks from the underlying system call say
The TerminateProcess function is used to unconditionally cause a process to exit. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.
A process cannot prevent itself from being terminated.
If you are creating the process you are killing, and have taken no extraordinary measures to raise its priviledges, or drop your own, there should be no circumstances in which the kill attempt will fail.
However, on later versions of the OS, it is possible for processes to be added to a Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE which can cause other processes that are part of the same job object to be terminated automatically. But the creating process has to cooperate for that to happen.
One point to note. You are passing '9' to the kill call--presumably based upon the *nix kill 9, pid meme. The value passed to the Kill method does not control how the process is terminated. Ie. it is not a signal value. It is simply the exit code that is returned to anyone calling GetExitCode() for the process you've killed. As such, you should chose a value that makes sense in the environment you are running.
For example 9, translates to The storage control block address is invalid. which doesn't make a lot of sense in this circumstance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Killing a process on Windows (Win32::Process question)
by rovf (Priest) on May 13, 2009 at 15:25 UTC | |
by BrowserUk (Patriarch) on May 13, 2009 at 15:44 UTC | |
by cdarke (Prior) on May 13, 2009 at 15:41 UTC | |
by BrowserUk (Patriarch) on May 13, 2009 at 15:50 UTC |