0

I have an interest in Operating Systems. So I am reading the xv6 book to understand Operating Systems. This is my first book on the subject. I read a line I couldn't understand.

Internally, the xv6 kernel uses the file descriptor as an index into a per-process table, so that every process has a private space of file descriptors starting at zero.

I thought that file descriptors represent data streams that can be written into or read from. How does that tie into the process table? Isn't the file descriptor table a part of the process's memory representing its open file resources?

Thanks in advance!

1
  • 3
    It says "per-process table", not "process table". "per-process table" == "separate tables specific to each process" Commented Jan 14, 2020 at 6:52

1 Answer 1

3

Your understanding of is correct. The file descriptor table is part of the individual process's memory (well the indexes into the table is available to the process, while the table itself is a kernel structure not directly accessible from the user-space process; but the table, or part of the table, is still specific to the process though).

This is also what the text says:

[...] uses the file descriptor as an index into a per-process table [...]

This is another way of saying "uses a file descriptor as an index into a table that is specific to each process".

7
  • To nitpick: the file descriptor table is not part of the process's memory, or at least not the part that is visible from user space. This is of course a bit of an implementation specific detail, but the thing Unix-like operating systems have in common is that open file handling is a kernel internal thing. The file descriptor table is not accessible from user space; the kernel hands out a small integer for each open file, and the file is referred to using this integer. In the Linux kernel, a file descriptor table is allocated using kmalloc for each process. Commented Jan 14, 2020 at 8:24
  • @JohanMyréen Thanks. I added a parenthesis about this. Does that sound correct to you? Commented Jan 14, 2020 at 10:21
  • 1
    Looks good to me. Commented Jan 14, 2020 at 12:07
  • @JohanMyréen FWIW, the Q is about xv6, a didactical rewrite a Unix version 6, obviously quite different from Linux or any modern Unix system. There are other questions about xv6 (with answers which badly miss the mark -- eg. this: there's no /dev/tty in xv6). An xv6 tag would probably be needed, but my experience with trying to add tags has not been the best ;-) Commented Jan 14, 2020 at 17:31
  • And no, the file descriptor table is not part of a process's memory, but of the kernel's memory (in both linux or xv6). It's just referenced from the process struct, which itself lives in kernel, not in user memory. Commented Jan 14, 2020 at 17:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.