Operating System - HP-UX
1755139 Members
2874 Online
108830 Solutions
New Discussion юеВ

Relationship between socket and file descriptor

 
Shivkumar
Super Advisor

Relationship between socket and file descriptor

Hi Guys,

Can anyone throw some light on what is the difference between socket and file descriptors on hpux 11i ?

What are the commands to find them ?

Thanks,
Shiv
3 REPLIES 3
Laurent Menase
Honored Contributor

Re: Relationship between socket and file descriptor

Hi,

a fildescriptor is how a process can see a socket, an open file, a pipe.
What sort of information do you want to get from filedesc and socket and files?

Amit Agarwal_1
Trusted Contributor

Re: Relationship between socket and file descriptor

What kind of difference are you looking for?

For second part of your query, If you are looking for open files for process , lsof command could be useful. You can download one from
ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/
A. Clay Stephenson
Acclaimed Contributor

Re: Relationship between socket and file descriptor

Sockets are actually implemented as file descriptors so all sockets are file descriptors but the converse is not true. The first step in the process is the socket() system call. It returns a small integer (a file descriptor) but no actual network connection exists at this point. The next step is to associate this file descriptor with a network connection and that is the job of the connect() or bind() system calls.

If you really want to understand the socket mechanism, I suggest that you look at Perl's IO::Socket module. The steps you do there are simplified versions of the same process in C; there's no easier way to build a client/server pair than with IO::Socket and the modules come with documentation and examples.

If you want to see open sockets on a running system, lsof is hard to beat. You can download it from any of the HP-UC Porting Centre's.
If it ain't broke, I can fix that.