Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket and file descriptors

Tags:

I'm learning about network programming in Unix and currently trying to understand the concept of socket and file descriptors. From what I have understood a file descriptor is simply a position in an array of pointers (File descriptor table?) and these pointers point to a file somewhere in memory.

Do socket descriptors share this array with file descriptors, but the pointer instead refers to a socket. Or is there something else that's only used for sockets?

Is this array unique to every application/process?

like image 915
Carlj901 Avatar asked Nov 14 '12 11:11

Carlj901


People also ask

Are sockets available in file descriptors?

There is no difference between a socket (descriptor) and a file descriptor(s). A socket is just a special form of a file. For example, you can use the syscalls used on file descriptors, read() and write(), on socket descriptors.

What is socket descriptor in Unix?

Sockets allow communication between two different processes on the same or different machines. To be more precise, it's a way to talk to other computers using standard Unix file descriptors. In Unix, every I/O action is done by writing or reading a file descriptor.

Is a socket a file?

A socket is a special file used for inter-process communication, which enables communication between two processes. In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

What are file descriptors used for?

A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.


1 Answers

Yes, sockets are also indices into the same table as files. At least for UNIX systems (like Linux and OSX), Windows is different, which is why you can't use e.g. read and write to receive and send data.

Each process has its own "file" descriptor table.

like image 172
Some programmer dude Avatar answered Sep 20 '22 02:09

Some programmer dude