Skip to content

Instantly share code, notes, and snippets.

@TripleDogDare
Last active September 9, 2023 00:20
Show Gist options
  • Save TripleDogDare/ada3ed2611c9e79bfc85d1ae8097b5c8 to your computer and use it in GitHub Desktop.
Save TripleDogDare/ada3ed2611c9e79bfc85d1ae8097b5c8 to your computer and use it in GitHub Desktop.
Get the PID of process listening on given TCP port
#!/bin/bash
set -eou pipefail
PORT=${1}
# Could use UDP here
lsof -iTCP:${PORT} | grep ${PORT} | tr -s ' ' | cut -d' ' -f2
#!/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