System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I find the port with reference to PID which is running on the server.

bullz
Super Advisor

How can I find the port with reference to PID which is running on the server.

Crew,

How can I find the port with reference to PID which is running on the server.
For example, assume PID is 1785

And I want to know which port number is mapped for PID 1785

root@chiti # ps -ef | grep ssh
root 1785 1 0 14:23:35 ? 0:00 /usr/lib/ssh/sshd
5 REPLIES
Goran Koruga
Honored Contributor

Re: How can I find the port with reference to PID which is running on the server.

Hello.

lsof -p 1785

netstat -nap | grep 1785

Regards,
Goran
bullz
Super Advisor

Re: How can I find the port with reference to PID which is running on the server.

thanx...

i got it with netstat -nap

but, how can figure out from command lsof?
can u explain the output of lsof which mentioned below.

root 9428 1 0 Oct22 ? 00:00:01 /usr/sbin/sshd

# lsof -p 9428
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
sshd 9428 root cwd DIR 104,5 4096 2 /
sshd 9428 root rtd DIR 104,5 4096 2 /
sshd 9428 root txt REG 104,2 409024 598371 /usr/sbin/sshd
sshd 9428 root mem REG 104,5 58683 /lib/libpam.so.0.81.5 (path inode=61307)
sshd 9428 root DEL REG 104,5 58584 /lib/libcrypto.so.0.9.8e.#prelink#.GvMDrd
sshd 9428 root mem REG 104,2 538362 /usr/lib/libnssutil3.so (path inode=543552)
sshd 9428 root mem REG 104,5 58681 /lib/libaudit.so.0.0.0 (path inode=61306)
sshd 9428 root mem REG 104,5 58573 /lib/libcrypt-2.5.so (path inode=58545)
sshd 9428 root mem REG 104,5 58583 /lib/libcom_err.so.2.1 (path inode=61303)
sshd 9428 root mem REG 104,2 538372 /usr/lib/libnspr4.so (path inode=543059)
sshd 9428 root DEL REG 104,2 543629 /usr/lib/libkrb5support.so.0.1.#prelink#.wmZE1l
sshd 9428 root mem REG 104,5 59434 /lib/libnsl-2.5.so (path inode=58529)
sshd 9428 root mem REG 104,5 50848 60754 /lib/libnss_files-2.5.so
sshd 9428 root mem REG 104,5 58576 /lib/libselinux.so.1 (path inode=59371)
sshd 9428 root mem REG 104,5 58543 /lib/libc-2.5.so (path inode=58521)
sshd 9428 root mem REG 104,2 543488 /usr/lib/libplc4.so (path inode=543458)
sshd 9428 root mem REG 104,2 543570 /usr/lib/libplds4.so (path inode=543542)
sshd 9428 root mem REG 104,5 58763 /lib/libpthread-2.5.so (path inode=58549)
sshd 9428 root mem REG 104,2 543683 /usr/lib/libz.so.1.2.3 (path inode=543571)
sshd 9428 root mem REG 104,5 59428 /lib/libdl-2.5.so (path inode=58531)
sshd 9428 root mem REG 104,5 58505 /lib/ld-2.5.so (path inode=58514)
sshd 9428 root mem REG 104,2 543689 /usr/lib/libk5crypto.so.3.1 (path inode=543687)
sshd 9428 root mem REG 104,5 59438 /lib/libutil-2.5.so (path inode=58547)
sshd 9428 root mem REG 104,5 58571 /lib/libwrap.so.0.7.6 (path inode=58512)
sshd 9428 root mem REG 104,2 543690 /usr/lib/libkrb5.so.3.3 (path inode=543767)
sshd 9428 root mem REG 104,5 61295 /lib/libresolv-2.5.so (path inode=58527)
sshd 9428 root mem REG 104,2 543611 /usr/lib/libnss3.so (path inode=543566)
sshd 9428 root mem REG 104,5 58570 /lib/libsepol.so.1 (path inode=58694)
sshd 9428 root DEL REG 104,2 543691 /usr/lib/libgssapi_krb5.so.2.2.#prelink#.A6rImB
sshd 9428 root mem REG 104,5 58577 /lib/libkeyutils-1.2.so (path inode=61302)
sshd 9428 root DEL REG 104,2 542443 /usr/lib/libfipscheck.so.1.1.0.#prelink#.daRjWZ
sshd 9428 root 0u CHR 1,3 1513 /dev/null
sshd 9428 root 1u CHR 1,3 1513 /dev/null
sshd 9428 root 2u CHR 1,3 1513 /dev/null
sshd 9428 root 3u IPv4 176345223 TCP *:ssh (LISTEN)


* I will assign the points in the end.
Patrick Wallek
Honored Contributor

Re: How can I find the port with reference to PID which is running on the server.

The key is this line:

>>sshd 9428 root 3u IPv4 176345223 TCP *:ssh (LISTEN)

This is listening on the 'ssh' port. By default this is port 22, as defined in /etc/services.
Patrick Wallek
Honored Contributor

Re: How can I find the port with reference to PID which is running on the server.

If you want to prevent lsof from converting port 22 to 'ssh' in its output you can do the following:

lsof -p 9428 -P

Then your line with the port info would look like:

sshd 9428 root 3u IPv4 176345223 TCP *:22 (LISTEN)
bullz
Super Advisor

Re: How can I find the port with reference to PID which is running on the server.

Thanx buddies......