Operating System - HP-UX
1850102 Members
2917 Online
104050 Solutions
New Discussion

process id's and portnumber

 
Amith_2
Frequent Advisor

process id's and portnumber

Could anyone please tell me why port numbers are used in network programming instead of process id's
4 REPLIES 4
Hemmetter
Esteemed Contributor

Re: process id's and portnumber

Hi Amith,

A network connection is defined through a socket={src-ip,src-port,dest-ip,dest-port}.

If you open a connection, say http, you know that you have to adress dest-port=80/tcp (http) because that service is "well-known" (see /etc/services).
If not portnumbers but PIDs would be used for dest-ports, how do you know the PID of httpd who serves www.google.com?

Or

If you, for example, replace the src-port with your browser-PID and you visit a site with lots of gifs your multithreaded browser will open lots of connetions, all with the same PID, how would your browser determine what ip-packet belongs to which gif?

Now this work is done for every application by the tcp/ip stack. The applications only specify the target and will get a handle back for further work with that connection.

Now if you want to know to what process opened a certain connection use lsof(8)
$ lsof -i @yourhost:src-port

hns@AVALON:/home/hns> lsof -i @avalon:52545
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 829 hns 3u IPv4 0xc4a23910 0t0 TCP avalon:52545->snowdon:ssh (ESTABLISHED)


A good source for reading is
R. Stevens "UNIX Network programming Vol.I"

rgds
HGH
Calandrello
Trusted Contributor

Re: process id's and portnumber

Friend
lsof |grep number-port
this goes to bring together numbers it of the process, that this leaving the door in Lock
Ivan Ferreira
Honored Contributor

Re: process id's and portnumber

Port numbers are not used instead of process id's. When you develop a network service, the program must start and listed in a network address/port to accept connections.

When the program starts, a PID is created for the process.

As many network services can be running in a server, you need a way to allow multiple services running on the same network address. There is where ports numbers plays. To avoid service conflicts, every network service listen on a different network port but in the same IP address.

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?