简体   繁体   English

int filedes? 系统调用读写

[英]int filedes? system calls read and write

Can any of you guys tell me what "int filedes" refers to? 你们中的任何人都可以告诉我“int filedes”是指什么? http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html

I've noticed I can put any int in there and it seems to work but I don't know what it's for... 我注意到我可以把任何int放在那里它似乎工作,但我不知道它是什么...

Thanks. 谢谢。

The very first sentence of the description says, "the file associated with the open file descriptor, fildes ". 该描述的第一句话说,“与打开文件描述符相关联的文件, fildes ”。 In other words, it indicates the file you're reading from. 换句话说,它表示您正在读取的文件。 If your read function call works no matter what file descriptor you pass it, your program isn't doing what you think it is. 如果您的read函数调用无论您传递的文件描述符是什么,那么您的程序就不会按照您的想法执行。

It's a file descriptor. 这是一个文件描述符。 See http://en.wikipedia.org/wiki/File_descriptor . http://en.wikipedia.org/wiki/File_descriptor Since it represents an offset to a table lookup of files and pipes, there may be multiple descriptors that could return valid data. 由于它表示文件和管道的表查找的偏移量,因此可能有多个描述符可以返回有效数据。 0=stdin and 2=stderr will exist by default, or you can look at the open function to create your own. 默认情况下,0 = stdin和2 = stderr,或者您可以查看open函数来创建自己的函数。

Somewhere inside the kernel, there is a table comprises of file descriptor entries on a per-process base. 在内核的某个地方,有一个表包含每个进程基础上的文件描述符条目。 A file descriptor is a structure which describes the state of the file. 文件描述符是描述文件状态的结构。 What kind of information has a file descriptor? 什么样的信息有文件描述符? First of all, position from which the next read/write operation can be performed. 首先,可以执行下一个读/写操作的位置。 Then, the access mode of the file, specified by the open system call. 然后,由打开的系统调用指定的文件的访问模式。 And last but not least, a data structure which represent the on-disk information of a file. 最后但并非最不重要的是,一种表示文件磁盘信息的数据结构。 In *nix, this is an inode structure. 在* nix中,这是一个inode结构。 Here, the main question to be answered is : Where resides the blocks of the file in the disk. 这里,要回答的主要问题是:在磁盘中驻留文件的块。 If you have an inode of a file in the memory, you can find quickly, where is the Nth block of the file(which means you don't need to parse the path every time, and scan each directory in the path to resolve the inode). 如果内存中有文件的inode,则可以快速找到文件的第N个块(这意味着您不需要每次都解析路径,并扫描路径中的每个目录以解决索引节点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM