Last active
September 9, 2023 00:20
-
-
Save TripleDogDare/ada3ed2611c9e79bfc85d1ae8097b5c8 to your computer and use it in GitHub Desktop.
Get the PID of process listening on given TCP 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
#!/bin/bash | |
set -eou pipefail | |
PORT=${1} | |
# Could use UDP here | |
lsof -iTCP:${PORT} | grep ${PORT} | tr -s ' ' | cut -d' ' -f2 |
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
#!/bin/bash | |
set -eou pipefail | |
PORT=${1} | |
ss -ltnp "( sport = :${PORT} )" | grep ${PORT} | tr -s ' ' | cut -f6 -d' ' | cut -f2 -d',' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment