#!/bin/bash

[[ $UID == 0 ]] || { echo "Run me as root!"; exit 1; }

declare -A sockets
while read -r file sock; do
	[[ $file =~ /proc/([0-9]+)/fd/[0-9]+ ]] || continue
	pid="${BASH_REMATCH[1]}"
	[[ $sock =~ socket:\[([0-9]+)\] ]] || continue
	inode="${BASH_REMATCH[1]}"
	sockets[$inode]=$pid
done < <(find -P /proc -maxdepth 3 -mindepth 3 -lname 'socket:\[*\]' -printf '%p %l\n' 2>/dev/null)

declare -a pids
while read -r _ _ _ _ _ _ _ _ _ inode; do
	[[ $inode == Inode ]] && continue
	pids+=( ${sockets[$inode]} )
done < /proc/net/netlink

ps "${pids[@]}"
