taskkill

On this page 7

taskkill is a built-in Windows command-line utility that terminates one or more running processes, identified by process ID (PID) or image name, on the local computer or on a remote system. It is the standard way in the Windows Command Prompt to stop a hung application, clean up after a failed script or end a runaway service process without opening Task Manager.

Within PowerShell & command line administration, taskkill is the natural partner of tasklist, which lists processes, and the older counterpart of the PowerShell cmdlet Stop-Process. It supports filters, process trees and forced termination, which makes it powerful but also easy to misuse.

How taskkill ends a process

taskkill ends a process either by asking it to close or by forcing immediate termination, and the difference determines whether the application can save its state. Without the /F switch, taskkill sends a close request, which for windowed programs means a WM_CLOSE message to their top-level windows; the program may save data, prompt the user or ignore the request.

With /F, taskkill calls the system’s TerminateProcess function. The process stops at once, its threads end, and the kernel releases its handles and memory, but no cleanup code in the application runs. Unsaved documents are lost, temporary files may remain and databases may need recovery. Console applications and background processes have no window to close, so taskkill typically reports that they can only be terminated forcefully.

The table below compares the two termination modes.

ModeMechanismApplication can save dataTypical use
Graceful (default)Close request to the process windowsYes, if it respondsNormal shutdown of desktop programs
Forced (/F)TerminateProcess system callNoHung programs and console processes
Tree (/T)Applies the chosen mode to child processes tooDepends on /FStopping a launcher and its workers
Graceful and forced termination

Syntax and key switches of taskkill

The general form is taskkill [/S system [/U user [/P password]]] {[/FI filter] [/PID id | /IM name]} [/T] [/F], and at least one target must be specified through a PID, an image name or a filter. Switches can be combined and repeated, for example several /PID values in one command.

The most important switches are summarized in the next table.

SwitchMeaningExample
/PIDTarget a process by its numeric IDtaskkill /PID 4312
/IMTarget by image name, wildcards allowedtaskkill /IM notepad.exe
/FForce terminationtaskkill /F /IM chrome.exe
/TInclude all child processestaskkill /T /PID 880
/FIApply a filter expressiontaskkill /FI "STATUS eq NOT RESPONDING"
/S, /U, /PRemote computer and credentialstaskkill /S srv01 /IM app.exe
Main taskkill switches

Filters use operators such as eq, ne, gt and lt on fields like STATUS, USERNAME, MEMUSAGE, CPUTIME, WINDOWTITLE, MODULES and SERVICES. A filter such as MEMUSAGE gt 500000 targets processes using more than about 500 MB of memory, since the value is given in kilobytes. Wildcards with /IM accept a trailing asterisk, so /IM app* matches every image name beginning with app.

taskkill returns an exit code of 0 on success and a non-zero code when it fails, for example 128 when no matching process exists. Batch files can test this with if errorlevel to decide whether to continue.

taskkill is one of several ways to stop processes on Windows, and the choice depends on the shell, the need for objects and remote access. The comparison below covers the common alternatives.

ToolInterfaceStrengthLimitation
taskkillCommand Prompt and batch filesFilters, trees, remote targetsText output only
Stop-ProcessPowerShell cmdletWorks with process objects in pipelinesNo built-in tree option
Task ManagerGraphical interfaceVisual overview and End task buttonNot scriptable
WMIC process deleteLegacy command lineWMI-based remote controlDeprecated and being removed
sc stopService Control ManagerClean stop of Windows servicesServices only, not arbitrary processes
Tools that terminate processes on Windows

For services, stopping through the Service Control Manager is preferred, because it lets the service shut down in an orderly way and keeps the service state consistent. taskkill with the SERVICES filter is a fallback when a service process will not respond.

Permissions, protected processes and failure cases

taskkill can only end processes that the caller has rights to terminate. A standard user can stop their own processes, while processes of other users, services running as SYSTEM and elevated programs require an elevated Command Prompt.

Some processes cannot be terminated at all from user mode. Critical system processes such as csrss.exe, protected processes like the Microsoft Defender service, and anti-malware processes running as protected process light return access denied even for administrators. Ending a critical process that is not protected can cause an immediate system crash.

Message or symptomLikely causeFix
Access is deniedInsufficient rights or protected processRun elevated, or stop the owning service properly
Process not foundWrong PID or image nameCheck with tasklist first
Can only be terminated forcefullyConsole or background processAdd /F after checking the impact
Process restarts immediatelyA service or watchdog relaunches itStop or disable the parent service
RPC server unavailableRemote firewall or service blockedAllow remote management or use PowerShell remoting
Common errors and their causes

Safe practices for scripts and administration

Reliable use of taskkill starts with identifying the exact target before terminating it. Running tasklist with the same filter first shows what would be affected and prevents accidental termination of unrelated processes.

  • Prefer PID over image name when several instances run and only one is faulty.
  • Try a graceful close first and add /F only after a timeout.
  • Use /T deliberately, because killing a parent shell can end unrelated child programs.
  • Avoid broad wildcards in scheduled tasks, where nobody reviews the matches.
  • Log exit codes in batch files so failed terminations are visible.

The simple explanation

taskkill is a typed command for closing programs. Instead of opening Task Manager and clicking End task, a person or a script writes the name or number of the program, and Windows closes it.

It can ask politely, giving the program a chance to save its work, or it can pull the plug immediately. The second option is useful when a program is frozen, but anything not saved is lost, so it is best used only when a normal close fails.

How it is used in practice

A help desk technician at a school supports 40 classroom computers. Every morning, a reporting tool occasionally freezes during startup and blocks a nightly batch job. The technician adds a step to the batch file that runs taskkill /FI "STATUS eq NOT RESPONDING" /IM report.exe, waits 30 seconds, then repeats the command with /F if the exit code shows the process is still running.

The script also writes the exit code to a log file. Over the next month, the frozen tool is closed automatically on nine occasions, the batch job completes every night, and the technician no longer needs to connect to each computer manually. The log shows that graceful closing worked in most cases, so data loss is avoided.