Identificar que proceso usa un puerto con pfiles
De Wikillano
Podemos identificar el proceso mediante este script:
#!/bin/bash
#
# 7-30-2003
# find from a port the pid that started the port
#
line='-------------------------------------------------------------------------'
pids=`/usr/bin/ps -ef | sed 1d | awk '{print $2}'`
# Prompt users or use 1st cmdline argument
if [ $# -eq 0 ]; then
read ans?"Enter port you like to know pid for: "
else
ans=$1
fi
# Check all pids for this port, then list that process
for f in $pids
do
/usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
if [ $? -eq 0 ] ; then
echo "$line\nPort: $ans is being used by PID: \c"
/usr/bin/ps -o pid -o args -p $f | sed 1d
fi
done
exit 0
ejemplo:
david@opensolaris:~$ ./pid 22 -------------------------------------------------------------------------\nPort: 22 is being used by PID: \c 637 /usr/lib/ssh/sshd
También podemos hacer lo siguiente:
pfiles /proc/* | egrep "^[0-9]|port: 22"
nos saldrá algo parecido a esto, buscaremos port: 22
627: /usr/lib/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_Noti
629: /usr/lib/gnome-netstatus-applet --oaf-activate-iid=OAFIID:GNOME_Netsta
631: /usr/lib/mixer_applet2 --oaf-activate-iid=OAFIID:GNOME_MixerApplet_Fac
633: /usr/lib/notification-daemon
634: /usr/lib/gnome-netstatus-wifi-info
636: /usr/lib/ssh/sshd
sockname: AF_INET6 ::ffff:172.24.51.2 port: 22
637: /usr/lib/ssh/sshd
sockname: AF_INET6 ::ffff:172.24.51.2 port: 22
640: -bash
7: /lib/svc/bin/svc.startd
9: /lib/svc/bin/svc.configd
