tags:

views:

100

answers:

2

I have a client tcp socket (in c++) that has a loop where it retries to open a socket and connect to a server at a certain interval until it succeeds.

A bug in the program caused close not to be called on the file descriptor after a failed connect, and the same (open) descriptor was used again when calling socket and connect in the next iteration of the loop when retrying to reconnect.

On Linux machines this did not cause any problems, while on HPUX it eventually cause a error 24 - 'Too many open files'' - lsof showed these as TCP *:* (IDLE).

What is the difference here between Linux and HPUX?

+2  A: 

I believe it comes from the origin in which HPUX added sockets to the kernel. If I remember correctly (from the late 1980s) they added Berkeley Sockets as a shareable object library—essentially a layer or two on top of the file i/o system.

That UX still behaves that way indicates the socket() call isn't reusing unused file descriptors, probably because it isn't aware of them, and no maintenance engineer has been tasked to add that. In Linux, socket() is as much as a part of the kernel as other major components, so of course it is aware of which file descriptors are available for reuse.

wallyk
Thanks for the info - makes sense then
A: 

It seems that the limit of files a process can open simultaneously is 60 by default on HPUX, while on Linux is 1024.

Jaime Soriano
On linux the unused file descriptor is not marked as idle and does not add to the process' fd count.