Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Created December 22, 2016 18:59
Show Gist options
  • Save xenithorb/1fc581f36a6d8f797a2109362a176456 to your computer and use it in GitHub Desktop.
Save xenithorb/1fc581f36a6d8f797a2109362a176456 to your computer and use it in GitHub Desktop.
List listening ports for a cgroup - bashrc style function
# Find listening ports of a service cgroup
# https://www.redpill-linpro.com/sysadvent/2016/12/22/systemd-at-3am.html
lsof_listen() {
local pids=$( ps -e -o pid,cgroup | awk '$2 ~ /'"$1"'/ { print "-p", $1 }' )
sudo lsof -n -i -a -P ${pids:?ERROR: No PIDs found.}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment