11

I'm unfamiliar with how processes are killed in Windows. In Linux, a "warm" kill sends a signal (15) which the process can handle by instantiating a signal handler. A cold kill is signal (9) which the OS handles by killing the process forcefully.

How can I "kill" a process in Windows? How is it handled by OS and by the process? What actions does OS perform? Is there a cross-platform way of responding to a kill/close request?

2
  • 3
    For readers: Signal 15 is SIGTERM, 9 is SIGKILL. – user1686 Jun 16 '10 at 17:06
  • Please accept an answer, if your question has been answered. – Oliver Mar 15 '14 at 10:28
13

"End Task" (and taskkill) appears to post a WM_CLOSE message to the program's windows. (The same is done when you click the × "Close" button.) If the program does not exit in some time, user gets prompted to end the program forcefully.

"Kill Process" and taskkill /f use TerminateProcess().

5
  • 2
    +1, WM_CLOSE sent to app; after X time ask user to force kill, Windows removes the process from the scheduler, closes all handles (which can trip up the process if the kernel is processing one of those handles), then reclaims the memory space (this is the really short version of the process). – Chris S Jun 16 '10 at 17:01
  • The third way is ntsd -p <pid> -c q, which uses the ntsd debugger; I'm not sure what happens when a program is killed that way. (pokes @Chris) – user1686 Jun 16 '10 at 17:08
  • 5
    what happens if the program doesn't have a window? – IttayD Jun 18 '10 at 11:46
  • 2
    @IttayD: Then there's no entry in Task Manager to use "End Task" on :) I just tried taskkill and it replies with: "This process can only be terminated forcefully ( with /F option )." So yeah, the only choice left is TerminateProcess(). – user1686 Jun 18 '10 at 20:20
  • 3
    @IttayD: Note that on Windows, services (daemons) are written differently from user applications; they can receive status queries and control requests from Service Manager, so a graceful stop is possible. – user1686 Jun 18 '10 at 20:22
0

Sysinternals (now part of Microsoft) offers a utility called pskill which can be used from the command line to kill processes on the local system or on remote systems.

The usual way to kill processes in Windows in a GUI environment is to use the Task Manager.

-1

with cygwin you can use a cross platform kill!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.