Luke Oliff.

TIL: Finding Processes on a Port With lsof -i

·TIL·1 min read·Luke Oliff

Port 3000 is already in use. The error message does not tell you by who. lsof does.

lsof -i :3000

Shows every process using port 3000. The output includes the PID, process name, and connection state.

lsof -i TCP:3000

Filter to TCP connections only. UDP filtering works the same way.

lsof -i :3000 | grep LISTEN

Find only the process that is listening on the port, not connections to it.

kill -9 $(lsof -t -i :3000)

The -t flag outputs PIDs only. Combine with kill to shut down whatever is holding the port without looking at the output.

What port ranges can I query?

Any port number from 1 to 65535. lsof shows both IPv4 and IPv6 listeners.

Does lsof require sudo?

Some processes are owned by other users. Run sudo lsof to see every process on every port.