Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bin/clear-port
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh

# Kills the process running on the provided port
# Kills the processes listening on the provided port
#
# clear-port 3000

if [ -n "$1" ]; then
port_num="$(lsof -ti4TCP:"$1")"
if [ $? -eq 0 ]; then
kill "$port_num"
fi
# A port can be held by more than one process, and a forked server's workers
# die with the parent, so signal every PID in a single kill.
lsof -ti4TCP:"$1" -sTCP:LISTEN | xargs -r kill
else
echo >&2 Usage: clear-port port-number
exit 1
Expand Down