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?
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
- Using PowerShell (Recommended)
- Using Task Manager
- Using Resource Monitor
- Alternative Methods
- Complete Step-by-Step Example
Using Command Prompt with netstat
The traditional method uses the netstat command to find which process is using a specific port:
-
Open Command Prompt (Press Win + R, type
cmd, and press Enter) -
Find the process using port 8080:
cmdnetstat -ano | findstr :8080This command will show you all connections related to port 8080. Look for lines where the local address shows
0.0.0.0:8080or127.0.0.1:8080and the state isLISTENING. The last column shows the PID (Process Identifier). -
Terminate the process using the PID:
cmdtaskkill /PID [PID] /FReplace
[PID]with the actual process ID number.
Note: If
taskkillencounters issues in certain terminal environments like older versions of Git Bash,tskillcan be an alternative, though it’s deprecated in modern Windows versions.
Using PowerShell (Recommended)
PowerShell offers more integrated and modern ways to handle network connections:
Method 1: Get-NetTCPConnection
For TCP ports (including 8080):
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:
$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
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
Get-NetUDPEndpoint -LocalPort 8080 | Select-Object LocalAddress, LocalPort, OwningProcess
Using Task Manager
For a graphical approach:
- Press Ctrl + Shift + Esc to open Task Manager
- Go to the “Details” tab
- Click “View” → “Select columns…”
- Check “PID” to see Process IDs
- Find the process using the PID you obtained from
netstator PowerShell - Right-click the process and select “End task”
Using Resource Monitor
For a more detailed view:
- Press Win + R, type
resmon, and press Enter - Go to the “Network” tab
- Click “TCP Connections”
- Look for the port (8080) in the “Local Port” column
- Note the PID and find the corresponding process
Alternative Methods
Using NPX (if you have Node.js installed):
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
# 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
# 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
# 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-NetTCPConnectionrequires 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
- How to Check Which Process Is Using Port 8080 - DZone
- 8080 is already in use – Peter’s Random Topic Library
- Checking Active TCP/IP Connections on Windows with PowerShell - Windows OS Hub
- How to check the active ports and processes on Windows with PowerShell - Askme4Tech
- Get-NetTCPConnection (NetTCPIP) - Microsoft Learn
- 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.