Friday, October 21, 2005

Is there a way to determine the PID associated with a socket ?

lsof

or

> Is there a way to determine the PID associated with a socket ?

Or using native commands without using lsof is to use pfiles.

cd /proc
pfiles * > /tmp/pfiles.out

search through pfiles.out for the process that has the socket open you
are interested in. i.e. there will be entries such as:

3771: /export/home/archiver/bin/myprocess
Current rlimit: 256 file descriptors
0: S_IFCHR mode:0666 dev:85,0 ino:191320 uid:0 gid:3 rdev:13,2
O_RDONLY|O_LARGEFILE
1: S_IFCHR mode:0666 dev:85,0 ino:191397 uid:0 gid:0 rdev:24,2
O_RDWR|O_LARGEFILE
2: S_IFREG mode:0644 dev:85,5 ino:17 uid:104 gid:1 size:139436
O_WRONLY|O_LARGEFILE
3: S_IFDOOR mode:0444 dev:293,0 ino:58 uid:0 gid:0 size:0
O_RDONLY|O_LARGEFILE FD_CLOEXEC door to nscd[200]
4: S_IFSOCK mode:0666 dev:287,0 ino:19574 uid:0 gid:0 size:0
O_RDWR
sockname: AF_INET 10.1.1.1 port: 9001
peername: AF_INET 10.1.1.2 port: 9001

pid 3771 has port 9001 open locally.

1 Comments:

Blogger BIJUCYBORG said...

Better still

cd /proc

pfiles * | grep -v "^ "

Gives more clarity.

2:43 PM  

Post a Comment

<< Home