Have you ever encountered issues starting a server or application because the required port is already in use? This common scenario can occur when a process doesn’t release its port properly—
perhaps due to a dropped SSH connection or an application crash. This guide provides detailed instructions for identifying and terminating processes holding onto specific ports across Windows, Linux, and macOS.
When an application runs, it binds to a specific port for network communication. If the application fails to release the port upon termination, the port remains occupied until one of the following occurs:
Knowing how to manually kill these processes is crucial for minimizing downtime and avoiding unnecessary system restarts.
Read: How to Close Ports on Linux and Windows Systems
8080 with your port number): netstat -ano | findstr :8080 The output will display the PID (e.g., TCP 0.0.0.0:8080 ... LISTENING 1234).
taskkill /PID 1234 /F The /F flag forces termination. Re-run the netstat command to confirm the port is free.
For Windows 10 and later, you can use a one-liner in PowerShell:
Stop-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess -Force Alternatively:
Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process Read: An introduction to Windows PowerShell for beginners
If you have npm installed, run:
npx kill-port 8080 This utility automatically identifies and terminates the process using the specified port.
netstat -ano | findstr :8080 tskill: tskill 1234 taskkill //PID 1234 //F Create a batch file (killport.bat) with the following script:
@ECHO OFF
set /P port="Enter port : "
echo Showing process running with port %port%
netstat -ano | findstr "PID :%port%"
set /P pid="Enter PID to kill : "
taskkill /pid %pid% /f
set /P exit="Press any key to exit..."
Add the file’s location to your PATH for system-wide access.
Read: Repeat Linux Commands Every X Seconds for Real-Time Monitoring, Automation & Precise Scheduling
sudo lsof -i :8080 sudo kill -9 1234 sudo kill -9 $(sudo lsof -t -i:8080) Read: How to Kill Processes in Linux: Beginner-Friendly Guide to Command Line Termination
Find and kill the process in one command:
sudo fuser -k 8080/tcp sudo netstat -tulpn | grep :8080 sudo kill -9 1234 lsof -i :8080 kill -9 1234 kill -9 $(lsof -ti:8080) If a process refuses to terminate:
taskkill /PID 1234 /F /T to also terminate child processes.sudo kill -9 1234 with elevated privileges.If the port stays occupied, it may be due to the socket entering a TIME_WAIT state. Wait 1-2 minutes or configure your application to use the SO_REUSEADDR option.
If multiple processes share the port, identify and terminate them individually:
sudo lsof -i :8080 | awk '{print $2}' | xargs sudo kill -9 -9).netstat helps diagnose network-related issues.Yes, forcefully terminating a process (using SIGKILL or the /F flag) does not allow it to perform cleanup operations, which can result in data loss if the process was writing data.
Review the process name along with its PID using commands like tasklist (Windows) or ps aux (Linux/macOS) before terminating.
This often occurs because the previous instance did not properly release the port, leaving it in a TIME_WAIT state.
Yes, most applications can be configured to use specific ports. On Linux, systemd socket activation can also manage port allocation.
Modern frameworks and servers typically implement signal handling to release ports on termination. For custom applications, ensure proper shutdown hooks are in place.
Windows: netstat -an
Linux/macOS: netstat -tuln
Effectively managing processes that occupy specific ports is a vital skill for developers and system administrators. This guide has detailed methods for Windows, Linux, and macOS to help you quickly identify and terminate problematic processes. Always exercise caution and verify before killing processes, especially on production systems.
By following these approaches, you can resolve port conflicts efficiently and maintain a stable development environment.
The post How to Kill Processes Using Specific Ports on Linux, Windows and MacOS appeared first on net2.
Here’s a clear and detailed how-to guide for how to deploy Keycloak on Ubuntu VPS.…
This article provides a guide to configure OpenLiteSpeed as a reverse proxy for Metabase. What…
The collaboration makes it easy to boot directly into Ubuntu from AMI’s UEFI firmware solutions…
Open source software is known for its ability to lower IT costs. But in 2025,…
What if you could work on real-world projects, shape cutting-edge technology, collaborate with developers across…
Enhanced Android device simulation, smarter diagnostics, and OIDC-enforced authentication The Anbox Cloud team has been…