NeuroAgent

How to Kill Process Using Port in Windows

Learn multiple methods to identify and terminate processes using specific ports like 8080 on Windows. Complete guide with Command Prompt, PowerShell, and Task Manager approaches.

Question

How can I identify and terminate the process using a specific port on localhost in Windows? For example, how do I free up port 8080 when another application is already using it?

NeuroAgent

To identify and terminate a process using a specific port like 8080 on localhost in Windows, you can use several built-in methods. Here are the most effective approaches:


Contents


Using Command Prompt with netstat

The traditional method uses the netstat command to find which process is using a specific port:

  1. Open Command Prompt (Press Win + R, type cmd, and press Enter)

  2. Find the process using port 8080:

    cmd
    netstat -ano | findstr :8080
    

    This command will show you all connections related to port 8080. Look for lines where the local address shows 0.0.0.0:8080 or 127.0.0.1:8080 and the state is LISTENING. The last column shows the PID (Process Identifier).

  3. Terminate the process using the PID:

    cmd
    taskkill /PID [PID] /F
    

    Replace [PID] with the actual process ID number.

Note: If taskkill encounters issues in certain terminal environments like older versions of Git Bash, tskill can be an alternative, though it’s deprecated in modern Windows versions.


PowerShell offers more integrated and modern ways to handle network connections:

Method 1: Get-NetTCPConnection

For TCP ports (including 8080):

powershell
Get-NetTCPConnection -LocalPort 8080 | Select-Object LocalAddress, LocalPort, State, OwningProcess

This gives you the process ID (OwningProcess) using port 8080.

Method 2: With Process Names

To get both the process ID and the actual process name:

powershell
$port = 8080
$connections = Get-NetTCPConnection -LocalPort $port
$processInfo = $connections | ForEach-Object {
    $process = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
    [PSCustomObject]@{
        LocalPort = $_.LocalPort
        ProcessId = $_.OwningProcess
        ProcessName = $process?.ProcessName
        State = $_.State
    }
}
$processInfo | Format-Table

Method 3: One-Liner to Find and Kill

powershell
Stop-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess -Force

This directly finds the process using port 8080 and terminates it.

Method 4: For UDP Ports

powershell
Get-NetUDPEndpoint -LocalPort 8080 | Select-Object LocalAddress, LocalPort, OwningProcess

Using Task Manager

For a graphical approach:

  1. Press Ctrl + Shift + Esc to open Task Manager
  2. Go to the “Details” tab
  3. Click “View” → “Select columns…”
  4. Check “PID” to see Process IDs
  5. Find the process using the PID you obtained from netstat or PowerShell
  6. Right-click the process and select “End task”

Using Resource Monitor

For a more detailed view:

  1. Press Win + R, type resmon, and press Enter
  2. Go to the “Network” tab
  3. Click “TCP Connections”
  4. Look for the port (8080) in the “Local Port” column
  5. Note the PID and find the corresponding process

Alternative Methods

Using NPX (if you have Node.js installed):

bash
npx kill-port 8080

Using Process Explorer (third-party tool):

Download Process Explorer from Microsoft Sysinternals for advanced process and port monitoring.


Complete Step-by-Step Example

Here’s a complete workflow to free up port 8080:

Method 1: Command Prompt

cmd
# Step 1: Find the process using port 8080
netstat -ano | findstr :8080

# Output example:
# TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       12345

# Step 2: Terminate the process (PID is 12345)
taskkill /PID 12345 /F

Method 2: PowerShell

powershell
# Step 1: Find the process and display information
Get-NetTCPConnection -LocalPort 8080 | Select-Object LocalAddress, LocalPort, State, OwningProcess

# Step 2: Terminate the process
Stop-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess -Force -ErrorAction SilentlyContinue

Method 3: PowerShell with Process Names

powershell
# Find the process name using port 8080
$processId = (Get-NetTCPConnection -LocalPort 8080).OwningProcess
$processName = (Get-Process -Id $processId).ProcessName
Write-Host "Process '$processName' (PID: $processId) is using port 8080"

# Terminate the process
Stop-Process -Id $processId -Force

Important Notes

  • Administrative privileges: Some operations may require running Command Prompt or PowerShell as Administrator
  • Multiple processes: If multiple processes use the same port, you’ll need to terminate each one
  • System processes: Be careful when terminating system processes (like PID 4 for system processes)
  • Port availability: After termination, wait a moment before trying to bind to the port again
  • PowerShell version: Get-NetTCPConnection requires PowerShell 4.0+ (Windows 8.1/Server 2012 R2 and later)

These methods should help you quickly identify and terminate any process using port 8080 or any other port on your Windows system.

Sources

  1. How to Check Which Process Is Using Port 8080 - DZone
  2. 8080 is already in use – Peter’s Random Topic Library
  3. Checking Active TCP/IP Connections on Windows with PowerShell - Windows OS Hub
  4. How to check the active ports and processes on Windows with PowerShell - Askme4Tech
  5. Get-NetTCPConnection (NetTCPIP) - Microsoft Learn
  6. How to Kill the Process Using a Port on Localhost in Windows - Medium

Conclusion

  • Command Prompt method is quick and doesn’t require PowerShell knowledge
  • PowerShell methods are more powerful and provide better process information
  • Task Manager offers a graphical interface for those who prefer mouse-based operations
  • Always be cautious when terminating processes, especially system processes
  • For regular port management, PowerShell commands are the most efficient approach

Choose the method that best suits your comfort level and specific requirements. For most Windows users, the PowerShell approach offers the best balance of simplicity and functionality.