Question

I was wondering what is a file descriptor of the network socket and how to get it? I believe it is a number?

Était-ce utile?

La solution

It is indeed a number and you get it by issuing the socket(2) system call. It is stored in the process's task_struct and you need it to send or receive data.

More exactly, the kernel uses the file descriptor to locate File Objects stored in the files_struct struct inside the task_struct. It behaves like a bitmap where the number of the file descriptor represents the position the File Object occupies inside that structure.

Autres conseils

What is 'the' network socket? If it's a socket you created, it will be the return value from socket() or accept(). If you're writing a daemon, the socket will be determined by whatever did the accept() on your behalf -- for example, /etc/xinetd will set it to 0, 1, and 2.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top