DISQUS

Tech-Recipes: Find out which process is holding which socket open | UNIX | Tech-Recipes

  • Anonymous · 5 years ago
    Actually, you can skip a whole step there... if you add the '-p' argument to netstat, it includes the PID of the process in question!

    So instead of netstat -an, try netstat -anp.
  • Anonymous · 5 years ago
    netstat -anp works on linux, but not Solaris :-(
  • Guest · 5 years ago
    Just use /usr/proc/bin/pfiles <pid> bit of a pain to do it in reverse (i.e. speicfy pid to get the port) but a simple script can rip thru it for you....

    echo "which port?> "
    read port

    for pid in `ps -ef -o pid | tail +2`
    do
    foundport=`/usr/proc/bin/pfiles $pid 2>&1 | grep "sockname:" | grep "por
    t: $port$"`
    if [ "$foundport" != "" ]
    then
    echo "proc: $pid, $foundport"
    fi
    done