Interview Prep/Linux/Rapid-Fire Commands

Show all listening services with their systemd unit.

IntermediateProductionRapid-Fire Commands
Answer
for pid in $(sudo ss -tlnpH | grep -oP 'pid=\K[0-9]+' | sort -u); do
  printf '%s %s\n' "$pid" "$(ps -o unit= -p "$pid")"
done

ps -o unit= prints the systemd unit owning a PID.

All Linux questions Roadmap: Linux

More on Rapid-Fire Commands