Skip to content
New — orchestrate a team of Mel agents from your terminal. Learn more about orchestrating Mel agents
← All guides

Guides · terminal

How to find which process is using a port

By Lalla Asmaa Alaoui, founder of Mel · Updated

On Mac and Linux, run lsof -i :3000 to see which process is using port 3000. On Windows, run netstat -ano | findstr :3000 and read the process ID in the last column.

You usually need this when a dev server fails with "address already in use" or EADDRINUSE. Often the culprit is an old copy of the same server still running in another tab. Replace 3000 with your port in every command below.

Mac and Linux

  1. Find the process.
lsof -i :3000

The COMMAND column shows the program name and the PID column its process ID. To see only programs listening on the port, and skip slow name lookups:

lsof -nP -iTCP:3000 -sTCP:LISTEN

If nothing shows but the port is still busy, the process may belong to another user. Try again with sudo in front.

  1. On Linux, ss is a good alternative. Many Linux systems ship ss even when lsof is missing.
ss -ltnp 'sport = :3000'

-l shows listening sockets, -t TCP, -n numbers instead of names, and -p the process. Without sudo, you only see the process for your own programs.

  1. Check what the process is before you stop it.
ps -p 12345 -o pid,command

Replace 12345 with the PID from step 1. Make sure it is the server you expect, not a database or another app you need.

  1. Stop it politely.
kill 12345

This asks the program to shut down cleanly. Wait a second and run step 1 again.

  1. Force it only if it will not stop.
kill -9 12345

-9 ends the process at once, without letting it save or clean up. Use it as a last resort.

Windows

  1. Find the process ID in Command Prompt or PowerShell.
netstat -ano | findstr :3000

Look for a line with LISTENING. The number at the end is the PID. findstr :3000 also matches ports such as 30001, so check the local address column ends in :3000.

  1. See which program it is.
tasklist /FI "PID eq 12345"
  1. Stop it.
taskkill /PID 12345

Add /F to force it if it will not close. Some processes need a Command Prompt opened with "Run as administrator".

  1. The PowerShell way.
Get-NetTCPConnection -LocalPort 3000 -State Listen |
  Select-Object LocalPort, OwningProcess, @{n='Name';e={(Get-Process -Id $_.OwningProcess).ProcessName}}

Then stop it with Stop-Process -Id 12345. Add -Force only if needed.

Prevent it next time

  • Stop dev servers with ctrl+C instead of closing the window.
  • Many frameworks let you choose another port, for example PORT=3001 npm start on Mac and Linux, or set PORT=3001 before npm start in Command Prompt. Whether PORT is read depends on your framework.
  • If the same port is always taken by a system service, pick a different default port for your project.

Doing it with Mel

In Mel, you can run every command above at the prompt, in your own shell. Each result is a block, so the PID stays visible while you type the next command. You can split the pane with ctrl+D and keep your server in one half and your checks in the other.

You can also ask in plain English. Press ctrl+enter (cmd+enter on macOS) and write: "Something is already using port 3000. Tell me what it is, and stop it only if it is an old dev server." The agent can run the right command for your system and read the result back to you. Stopping a process is a command that changes your system, so with Mel's approvals the kill or taskkill shows on an approval card first, and you can deny it.

FAQ

What does "address already in use" mean? Another process is already listening on that port. Find it with lsof -i :PORT on Mac and Linux, or netstat -ano | findstr :PORT on Windows.

Why does lsof show nothing even though the port is busy? The process may belong to another user or to the system. Run sudo lsof -i :3000. On Linux you can also try sudo ss -ltnp.

Is kill -9 safe? It works, but the program gets no chance to save data or clean up. Try a plain kill first.

How do I free a port on Windows? Find the PID with netstat -ano | findstr :PORT, then run taskkill /PID <pid>. Add /F if it does not close.

Can I just use a different port? Yes. Most dev servers accept a port setting. That avoids stopping something you might need.

Mel – the agentic terminal · openmel.dev. A multi-agent, multi-model AI terminal for Mac, Windows, Linux and VS Code. Free with your own API key.

Lalla Asmaa Alaoui
Written by
Lalla Asmaa Alaoui
Founder & CEO of Mel

Lalla is a hands-on tech founder, agentic infrastructure architect and the vision behind Mel.

Follow on LinkedIn

Get started

Try the agentic terminal.

The Mel terminal is free to download, no account needed. The AI agent is free on your own provider key — 1,500 hosted-AI credits a month on Pro.