How to Kill a Process and Free Up a Port on Mac, Linux & Windows
You’ve started your local dev server and hit a dreaded error: “port 3000 is already in use.” It happens to every developer. Here’s the fastest way to find and kill the offending process on any operating system.
macOS
Step 1: Find the Process ID (PID)
sudo lsof -i :3000
Replace 3000 with your actual port number. The output will show the process using the port — copy the PID from the second column.
Step 2: Kill the Process
kill PID
Replace PID with the number you copied. If the process doesn’t terminate, try:
kill -9 PID
# or if you need elevated permissions:
sudo kill -9 PID
-9sends aSIGKILLsignal — the process cannot ignore or defer it.
Linux
Step 1: List All Running Processes
top
This gives you a live view of all processes and their PIDs. For a port-specific search, use:
sudo lsof -i :3000
Step 2: Kill the Process
kill PID
To kill by process name instead of PID:
killall process-name
For forceful termination:
kill -9 PID
# or
sudo kill -9 PID
Windows
Step 1: Find the Process ID (PID)
Open Command Prompt and run:
netstat -ano | findstr :3000
Replace 3000 with your port. The last column in the output is the PID.
Step 2: Kill the Process
taskkill /PID 12345 /F
Replace 12345 with the PID you found. The /F flag forces termination.
Verify the port is free by running the netstat command again.
Best Practices
| Approach | When to Use |
|---|---|
kill PID | First attempt — graceful termination |
kill -9 PID | Process is unresponsive to graceful signals |
sudo kill -9 PID | Process is owned by root or another user |
taskkill /F | Windows force kill |
Warning: Forceful termination (
-9//F) can cause data loss if the process hasn’t flushed buffers. Always try graceful termination first.
Quick Reference
# macOS / Linux — find PID
sudo lsof -i :PORT
# macOS / Linux — kill gracefully
kill PID
# macOS / Linux — kill forcefully
kill -9 PID
# Windows — find PID
netstat -ano | findstr :PORT
# Windows — kill forcefully
taskkill /PID PID /F
These commands are essential tools in any developer’s toolkit. Bookmark this page for the next time a zombie process is holding your port hostage.