質問

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

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top