Windows: TaskKill – Kill Process by PID, Name, Port – CMD

Sometimes when an application in Windows hangs, freezes and stops responding the only way to terminate it is to kill from the command-line.

The taskkill command in Windows serves for terminating tasks by name or by process id (PID).

In this note i am showing how to find and kill a process by its name or by PID and how to identify a process by the listening port.

I am also showing how to troubleshoot “The process could not be terminated” and “Access denied” errors.

Cool Tip: Get the return code from the last command or application! Read more →

Kill Process by Name

List all Windows processes and find the full name of a process to kill (case insensitive):

C:\> tasklist | findstr /I process_name

Kill the process by name:

C:\> taskkill /IM process_name.exe

Kill Process by PID

List all Windows processes and find the PID of a process to kill (case insensitive):

C:\> tasklist | findstr /I process_name

Kill the process by PID:

C:\> taskkill /PID process_id

Kill Process by Port

List all Windows processes listening on TCP and UDP ports and find the PID of a process running on a specific port:

C:\> netstat -ano | findstr :port

Find the name of a process by its PID:

C:\> tasklist /FI "pid eq process_id"

Kill the process by name or by PID:

C:\> taskkill /IM process_name.exe
- or -
C:\> taskkill /PID process_id

Cool Tip: Windows grep command equivalent in CMD and PowerShell! Read more →

Troubleshooting

Kill the process forcefully in case of the following error:

ERROR: The process with PID XXX could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

C:\> taskkill /F /IM process_name.exe
- or -
C:\> taskkill /F /PID process_id

If you get an “Access is denied” error, you should open the command prompt as an administrator:

ERROR: The process with PID XXX could not be terminated.
Reason: Access is denied

To run the CMD as an administrator, press Win keybutton to open the start menu, type in cmd to search for the command prompt and press Ctrl+Shift+Enter to launch it as administrator.