Which port is used by which process ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Which port is used by which process ?
# 1  
Old 06-04-2009
Which port is used by which process ?

Hi all,

I work in three platforms SOLARIS,HPUX,AIX.

My requirement is to find the user id which is using a particular port.
So I tried searching commands which will help me to know which port is used by which process.
According to the posts over here lsof makes life easy in this case. But I dont have lsof installed on my unix box neither I am allowed to install.
I also tried various combinations of netstat command, but none worked.

Please do help me.

Thanks,
Vikas
# 2  
Old 06-04-2009
In theory...

If you know the port number, you can see what process uses that port by grepping in /etc/services. Then, once you have that process name, you can

Code:
 
ps -ef | <process name>

and find the terminal. Then run

Code:
who -a | grep <terminal>

And you'll find the IP address and potentially the username. That'll get you close.

In theory... Smilie
# 3  
Old 06-05-2009
I checked the services file available in /etc.
But that showed me the system ports that are enabled.

Hence one will not be able to decipher which port is being used by which process.

Thanks,
Vikas
# 4  
Old 06-08-2009
Is there no way out other than lsof...???
# 5  
Old 06-09-2009
On Solaris you can use the pfiles utility.
Code:
PORT=    #set it to the port number whose assocated process you want to find.
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
        /usr/proc/bin/pfiles $pid 2>/dev/null | grep -q "port: $PORT"
        if [[ $? -eq 0 ]] ; then
               echo "Port: $PORT is being used by PID: \c" 
                           ps -o pid -o args -p $PID | sed 1d
        fi
done

Other OSes have similar functionality. You just need to search for it.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. IP Networking

Get process id and port from the socket

Hello, Please help me in getting the process id and the port number from the socket netstat -Aan|grep -i closed f100050010b133b8 tcp 0 0 *.* *.* CLOSED f1000500119b53b8 tcp4 0 0 *.* *.* ... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

2. IP Networking

Tcp ip port open but no such process (merged: Release A Port)

i want to kill a tcp connection by killing its pid with netstat -an i got the tcp ip connection on port 5914 but when i type ps -a or ps-e there is not such process running on port 5914 is it possible that because i do not log on with proper user account i can not see that process running? (30 Replies)
Discussion started by: alinamadchian
30 Replies

3. Solaris

To get process id for port number

Hi All, How to get the list of port numbers and it is correspoding proceses id that are currently running on. Please suggest and it is urgent Thanks. (7 Replies)
Discussion started by: rbalaj16
7 Replies

4. AIX

Process running on which port

I would like to know, how to find that particular process is running on which port other than /etc/services as this file shows well known ports information Double post, continued here. If you want answers for different OS, post in a general section instead. If you want your other post moved... (0 Replies)
Discussion started by: amity
0 Replies

5. Solaris

Process running on which port

Hi I would like to know, how to find that particular process is running on which port other than /etc/services as this file shows well known ports information. (1 Reply)
Discussion started by: amity
1 Replies

6. IP Networking

Port that a process opens up

Hi all, I have a process with PID as 12456. Could you please let me know how do i find out what is the port that process listens upon in Linux? Thanks in Advance, Pankajakshan (2 Replies)
Discussion started by: Pankajakshan
2 Replies

7. Linux

Port that a process opens up

Hi all, I have a process with PID as 12456. Could you please let me know how do i find out what is the port that process listens upon in Linux? Thanks in Advance, Pankajakshan (1 Reply)
Discussion started by: Pankajakshan
1 Replies

8. AIX

Process ID using IP Port

Is there a way in AIX to determine which process is connected to a particular IP port? I know about the lsof command, but for various reasons I can't install it on the machine I want to use it on. Is there a way other than using this command? (1 Reply)
Discussion started by: dgiaimo
1 Replies

9. Solaris

Which process is on which port....

Is there a way in Solaris to find which process is using which port? (3 Replies)
Discussion started by: Kraas
3 Replies
Login or Register to Ask a Question