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.

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  

Troubleshooting

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  

ERROR: The process with PID XXX could not be terminated.

Reason: Access is denied