connection start per pid
netstat -tap --numeric-port 2>/dev/null |\
awk 'NR >2 { print $6,$4,$5,substr($7,0,index($7, "/")-1);}' |\
sort -ru |\
awk -v pids="$1" 'BEGIN {OFS=","} { port=substr($2,index($2,":")+1) } pids !~ $4 {next} /LISTEN/ { listen[port]=1; $1="LIS"; print $0; next} { (port in listen)?$1="IN":$1="OUT"; print $0 }'