-
-
Save gerrard00/a08918dddc65a7bb2d814756b28ed2a1 to your computer and use it in GitHub Desktop.
pwdx for mac. Usage: pwx pid also portpwdx that finds the pwd for the process that owns a port. Usage: portpwdx port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pwdx { | |
# note: NF is the number of columns, so $NF gives us the last column | |
lsof -a -p $1 -d cwd -n | tail -1 | awk '{print $1, "\t", $NF}' | |
} | |
function portpwdx { | |
# pid=$(lsof -i :5858 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/') | |
pid=$(lsof -i :$1 | tail -1 | perl -pe 's/[^\s]+\s+([^\s]+)\s.*/$1/') | |
if [[ ! -z $pid ]]; then | |
echo $pid | |
pwdx $pid | |
return 0 | |
else | |
echo "No process listening to port $1" | |
return -1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Damn, what's holding that port open? Oh, ok netstat says node. But wait, which node process?
Ah:
portpwdx 8080
will show: