Table of Contents
When a port is already in use, services fail to start and return errors like address already in use. Identifying the process holding the port is the fastest fix.
Step 1: Check All Listening Ports
List all active listening ports and their associated processes.
ss -tulnp
This shows the port number, protocol, and process name.
Step 2: Check a Specific Port
If you already know the port number, filter the output.
sudo ss -tulnp | grep :3000
Replace 3000 with the port you are investigating.
Step 3: Identify the Process Using the Port
Use lsof to directly map the port to a running process.
sudo lsof -i :3000
The output shows the process name and PID.
Step 4: Stop the Process Safely
If the process is not needed, stop it gracefully.
sudo kill PID
Replace PID with the actual process ID.
Step 5: Force Kill a Stuck Process
If the process does not stop, force termination.
sudo kill -9 PID
Use this only when normal termination fails.
Optional Step: Check Common Ports
Quick checks for common services.
sudo ss -tulnp | grep :80
sudo ss -tulnp | grep :443
sudo ss -tulnp | grep :22
Helpful when debugging web servers, SSH, or reverse proxies.
