16

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
  • 5
    For readers: Signal 15 is SIGTERM, 9 is SIGKILL. Jun 16, 2010 at 17:06
  • 1
    Please accept an answer, if your question has been answered.
    – Oliver
    Mar 15, 2014 at 10:28

3 Answers 3

15

"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
  • 3
    +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, 2010 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) Jun 16, 2010 at 17:08
  • 9
    what happens if the program doesn't have a window?
    – IttayD
    Jun 18, 2010 at 11:46
  • 4
    @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(). Jun 18, 2010 at 20:20
  • 4
    @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. Jun 18, 2010 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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .