Skip to main content
Sometimes you need to terminate a process that’s using a specific port, especially when developing applications.
1

Find process using port (example: 3000)

Identify which process is using the port:
sudo lsof -t -i:3000
This command returns the Process ID (PID) of the process using port 3000.
2

Kill process

Terminate the process using its PID:
sudo kill -9 $(sudo lsof -t -i:3000)
The -9 flag forces the process to terminate immediately.
3

Verify port is free

Check that the port is now available:
sudo lsof -i:3000
If no output is shown, the port is free.
4

Done

The process is terminated and the port is now available for use.

Alternative methods

Using netstat

# Find process
sudo netstat -tulpn | grep :3000

# Kill by PID
sudo kill -9 <PID>

Using ss command

# Find process
sudo ss -tulpn | grep :3000

# Kill by PID
sudo kill -9 <PID>

Using fuser

# Kill process on port
sudo fuser -k 3000/tcp

Common port conflicts

Development servers

  • Port 3000 - React development server
  • Port 8080 - Common web server port
  • Port 5000 - Flask development server
  • Port 8000 - Django development server

Database ports

  • Port 5432 - PostgreSQL
  • Port 3306 - MySQL
  • Port 27017 - MongoDB

Safety tips

Check what you’re killing

# See process details before killing
ps aux | grep <PID>

Use graceful shutdown first

# Try graceful termination first
sudo kill <PID>

# Force kill if needed
sudo kill -9 <PID>

Check for multiple processes

# List all processes on a port
sudo lsof -i:3000

Troubleshooting

Permission denied

# Use sudo for system processes
sudo lsof -i:3000

Port still in use

# Check if process restarted
sudo lsof -i:3000

# Check for zombie processes
ps aux | grep defunct

Next Steps

Now you can:
  • Free up ports for development
  • Troubleshoot port conflicts
  • Manage running services
  • Restart applications cleanly

Build docs developers (and LLMs) love