lsof

CLI

List open files and the processes that opened them.

Find which process has a file or port open

4 of 4 recipes verified by execution · 2026-09-17#files#processes#network#sockets

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

Verified macOS · Linux · 2026-09-17
lsof -nP -iTCP:3000 -sTCP:LISTEN
Common failures (1)
  • no outputnothing is listening on that port, or the process belongs to another user: retry with sudo
Fallbackss -ltnp 'sport = :3000'

Kill the process listening on a port

Verified macOS · Linux · 2026-09-17
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)
Common failures (1)
  • kill: not enough argumentsthe port is already free (lsof -t printed nothing)
Fallbackfuser -k 3000/tcp

Find the process listening on a port (Linux, no lsof)

Linux only

Verified Linux · 2026-09-17
ss -ltnp 'sport = :3000'

Kill the process on a port (Linux, no lsof)

Linux only

Verified Linux · 2026-09-17
fuser -k 3000/tcp

Install

Homebrewbrew install lsof
aptsudo apt install lsof

Agent notes

When to use
Debugging 'port in use' errors or finding processes holding files
Quick examples
  • lsof -i :3000 # what's using port 3000
  • lsof -p 1234 # files opened by PID
  • lsof /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.

Homepage ↗SMAIL0 views