什么是文件描述符,用简单的术语解释? [英] What are file descriptors, explained in simple terms?

查看:106
本文介绍了什么是文件描述符,用简单的术语解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 与Wikipedia相比,对文件描述符的更简单描述是什么?为什么需要它们?以外壳程序为例,它如何应用?

  1. What would be a more simplified description of file descriptors compared to Wikipedia's? Why are they required? Say, take shell processes as an example and how does it apply for it?

一个进程表是否包含多个文件描述符.如果是,为什么?

Does a process table contain more than one file descriptor. If yes, why?

推荐答案

简单来说,当您打开文件时,操作系统将创建一个条目来表示该文件并存储有关该打开文件的信息.因此,如果您的操作系统中打开了100个文件,则操作系统中(内核中的某个位置)将有100个条目.这些条目由整数表示,例如(... 100,101,102 ....).该条目号是文件描述符. 因此,它只是一个整数,唯一表示操作系统中打开的文件. 如果您的进程打开了10个文件,那么您的进程"表将有10个文件描述符条目.

In simple words, when you open a file, the operating system creates an entry to represent that file and store the information about that opened file. So if there are 100 files opened in your OS then there will be 100 entries in OS (somewhere in kernel). These entries are represented by integers like (...100, 101, 102....). This entry number is the file descriptor. So it is just an integer number that uniquely represents an opened file in operating system. If your process opens 10 files then your Process table will have 10 entries for file descriptors.

类似地,当您打开网络套接字时,它也由整数表示,称为套接字描述符. 我希望你能理解.

Similarly when you open a network socket, it is also represented by an integer and it is called Socket Descriptor. I hope you understand.

这篇关于什么是文件描述符,用简单的术语解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆