lsof
CLIList open files and the processes that opened them.
Find which process has a file or port open
Verified commands
Executed by our harness on the platforms shown; the assertion checked the actual result, not just the exit code.
Find the process listening on a port
lsof -nP -iTCP:3000 -sTCP:LISTENCommon failures (1)
- no outputnothing is listening on that port, or the process belongs to another user: retry with sudo
Fallback
ss -ltnp 'sport = :3000'Kill the process listening on a port
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)Common failures (1)
- kill: not enough argumentsthe port is already free (lsof -t printed nothing)
Fallback
fuser -k 3000/tcpFind the process listening on a port (Linux, no lsof)
Linux only
ss -ltnp 'sport = :3000'Kill the process on a port (Linux, no lsof)
Linux only
fuser -k 3000/tcpInstall
Homebrew
brew install lsofapt
sudo apt install lsofAgent notes
- When to use
- Debugging 'port in use' errors or finding processes holding files
- Quick examples
lsof -i :3000 # what's using port 3000lsof -p 1234 # files opened by PIDlsof /var/log/app.log # who has this file open
Use from an agent
curl -s https://clihub.com/api/tools/lsof | jq '.agentHints.provenRecipes[] | {task, command, verified}'Or call get_tool with slug lsof on the MCP server at https://clihub.com/mcp.