Skip to content

Instantly share code, notes, and snippets.

@martin-cotta
Last active April 6, 2022 15:59
Show Gist options
  • Save martin-cotta/f8335efa8a398cf8e12fc91b63dc610b to your computer and use it in GitHub Desktop.
Save martin-cotta/f8335efa8a398cf8e12fc91b63dc610b to your computer and use it in GitHub Desktop.
Kill process on specific port
# sudo lsof -i :<PortNumber>
# kill -9 <PID>
# or
# kill -9 $(lsof -ti:<Port>, <Port>)
# The -t flag removes everything but the PID from the lsof output
# Error: listen EADDRINUSE: address already in use ::::3000
$ lsof -i tcp:3000
# COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
# node 44475 chen5 31u IPv4 0x8b1721168764e4bf 0t0 TCP *:strexec-s (LISTEN)
$ kill -9 44475
# or
$ kill -9 $(lsof -ti:3000)
#or
npx kill-port 3000
# or
$ lsof -ti:3000 | xargs kill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment