in *nix ~ read.

How to retrieve process info by its port on Solaris

I've never got any problems with finding process info by its port number. Every man who has ever worked with Linux knows about netstat:

netstat -p |grep :8010

tcp    0    0*    LISTEN    2122/kopete  
udp    0    0*              2122/kopet  

or lsof:

lsof -i :8010 | grep LISTEN

kopete  2122 mikhail 17u  IPv4 17717 0t0  TCP *:8010 (LISTEN)  

Somebody even knows about fuser:

fuser -n tcp 8010

8010/tcp:  2122  

But all these commands do not matter under Solaris!

All we have (on Solaris 5.10) is a /proc filesystem (with list of current processes) and Solaris utility pfiles, which allows us to see files associated with a process. So, the only way to solve this task is a little shell script:


for pid in `ls /proc`  
pfiles $pid | grep AF_INET | grep $1  
if [ $? -eq 0 ]; then  
    echo $pid

Yes, it looks terrible. Moreover I really don't understand why I must modificate a proprietary operation system... But let's get back to process info.

Once we have a process PID, we can retrieve any info about it:

/usr/ucb/ps auxvv | grep 2122

mikhail   2122  0.1  0.5 148096 35152 ?   Sl   19:58   0:02 /usr/bin/kopete -session XXX  
ls -l /proc/2122/exe

lrwxrwxrwx 1 mikhail mikhail 0 Oct 19 19:58 /proc/2122/exe -> /usr/bin/kopete  
comments powered by Disqus