nowadays, I am studying OS.

In Communication in Client-Server Systems chapter, I've heard that using process-id instead of port-number has problems.

But I don't understand why it does.

I think using ip+pid is possible because each process has their own process-id (pid). Is my thought wrong?

closed as unclear what you're asking by user22815, durron597, JB King, Ixrec, GlenH7 Nov 11 '15 at 22:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I've rolled over the process table index! Whee! I've got.... pid 80. :(. – user40980 Oct 28 '15 at 18:05
  • @MichaelT rolled over the process table index? – Danny_Kim Oct 28 '15 at 18:07
  • From Process identifier: "Process IDs are usually allocated on a sequential basis, beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases. In Mac OS X and HP-UX, allocation restarts at 100. " -- ok, so I don't get 80. I've got 443 instead. – user40980 Oct 28 '15 at 18:08
  • Process id may be unique (on a given machine), but it's not stable (it can change at any time: reboot, crashes). – Sjoerd Job Postmus Oct 28 '15 at 18:10
  • I thought parent process(server) can know child(client)'s pid from the return value of fork function. Then, parent process notify its own pid to child. Therefore, they can know their pid when program is started. Is this idea wrong? – Danny_Kim Oct 28 '15 at 18:46

The first and foremost issue stability. Port 25 is SMTP. Port 70 is gopher. Port 80 is http. And so on. These are established, known and assigned numbers. They have meaning between systems that are dissimilar.

The port number needs to be stable. You can't always run the mail process as process 25. You've got no guarantee about what order it launches in and in the event you have to kill and restart it, you have no guarantee on what process ID it would be.

Next off, consider that not all systems that have ports have processes (or processes that have a number). Consider a hypothetical web server appliance. You stick a USB drive in it, it serves files from it. That's it. One process, that just keeps serving files - would that be port 1? or would it need to be assigned some number that has meaning to others? Or my ancient Macintosh Plus that ran system 6 and had a web server. No numbers. So you need some other way to designate the port that a given bit of code is listening to.

There are applications that have multiple numbers. That web server not only listens on port 80, but 443 and maybe 8080 (not to mention the "this machine has multiple IP addresses, this process running on the machine listens to 80 on this, and 80 and 443 on that one, and 8080 on this other one"). If the system was bound to a process id it couldn't listen to different ports for different protocols.

By having assigned numbers, there is consistency across the network. Telnet is port 23. That telnet program opens up a connection to port 23 and knows what protocol is associated with what listens there. FTP listens uses ports 20 and 21 for different parts of its protocol - again, consistency. Having a consistent set of rules, numbers, and protocols is what makes the internet go 'round.

  • 1
    Wow, I'm impressed with the nice answer. Examples help me to understand easily, thank you very much – Danny_Kim Oct 28 '15 at 18:54
  • I didn't know there could be animals listening on a port. – edmz Oct 28 '15 at 19:02
  • 2
    @black gopher was the predecessor of the web - designed at the University of Minnesota, with its mascot - the gopher. Its "google" was Veronica (as opposed to Archie which was for FTP) - the name stood for "Very Easy Rodent-Oriented Net-wide Index to Computer Archives". Ahh... the 90's. – user40980 Oct 28 '15 at 19:07
  • Just so it's said...it'd be possible, almost trivial, to have a service that responds to queries for a given service (eg: "https") and sends back a number to refer to it. An RPC port mapper does something much like this.(It uses port numbers rather than pids, but the effect is similar.) Such a service would invalidate most of these arguments. – cHao May 25 '17 at 21:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.