Linux
lsof -i:{$port}
pwdx {$pid}
[user@hostname ~]$ lsof -i:8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME xxxxxx 2747 user 8u IPv4 930730699 0t0 TCP *:web (LISTEN) [user@hostname ~]$ pwdx 2747 2747: /ssd1/webroot
Mac
lsof -i:{$port}
lsof -a -p {$pid} -d txt -Fn | cut -c2- | grep -E "(S|w|s)*.app(S|w|s)*.[a-zA-Z]*" -v | grep -E "(S|w|s)*.[a-zA-Z]{1,6}$" -v | grep app
lsof -a -p {$pid} -d cwd -Fn | cut -c2- | grep -v {$pid}
➜ lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME WeChat 35377 user 32u IPv6 0xcd806161671b7807 0t0 TCP 1.x.x.x:60583->2.x.x.x:http (ESTABLISHED) ➜ lsof -a -p 35377 -d txt -Fn | cut -c2- | grep -E "(S|w|s)*.app(S|w|s)*.[a-zA-Z]*" -v | grep -E "(S|w|s)*.[a-zA-Z]{1,6}$" -v | grep app /Applications/WeChat.app/Contents/MacOS/WeChat /Users/user/Library/Containers/com.tencent.xinWeChat/Data/Documents/MMappedKV/mmkv.default /Users/user/Library/Containers/com.tencent.xinWeChat/Data/Documents/MMappedKV/maycrashcpmap_v2 /Users/user/Library/Containers/com.tencent.xinWeChat/Data/Documents/MMappedKV/0.mmkv.default /Users/user/Library/Containers/com.tencent.xinWeChat/Data/Documents/MMappedKV/hascrashcpmap_v2