Skip to content

Instantly share code, notes, and snippets.

@yesmeck
Created June 5, 2017 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yesmeck/be0537e9515399c9e6916530dbf43c76 to your computer and use it in GitHub Desktop.
Save yesmeck/be0537e9515399c9e6916530dbf43c76 to your computer and use it in GitHub Desktop.
detect which command using port
#!/bin/sh
port=$1
pid=`lsof -i :${port} -P -t -sTCP:LISTEN`
dir=`lsof -p ${pid} | awk '$4=="cwd" {print $9}'`
cmd=`ps -o command -p ${pid} | sed -n 2p`
echo "${cmd} in ${dir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment