Skip to content

Instantly share code, notes, and snippets.

@banjeremy
Created April 9, 2021 14:18
Show Gist options
  • Save banjeremy/29c80492ac4511b26133002854bff307 to your computer and use it in GitHub Desktop.
Save banjeremy/29c80492ac4511b26133002854bff307 to your computer and use it in GitHub Desktop.
get pid for a process running on a port
whatsonport () {
if [ $# -eq 1 ]
then
lsof -i :$1 | awk '{ print $2; }' | head -n 2 | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} -v PID
else
echo "Usage: whatsonport [port]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment