Lecture 3-1 - More on Processes Flashcards
What are “handles”?
It’s an array in the process space that allows I/O access as well as read write to files. Each index of the array corresponds to a device.
Where are the handles stored?
In the kernel memory space.
What are the handles 0, 1, and 2 used for by default?
Why do we separate 1 and 2?
- Stdin
- Stdout
- Stderr
By having error separate from stdout, we can separate them out as needed
What’s another name for handles?
File Descriptors.
Does a parent and a child share the same file descriptor?
No.
Can we change the default file descriptors?
Yes.
When are the default file descriptors created?
At process creation.
What does the open(“filename”, …) function do?
It returns a file descriptor pointing to the given file. You can think that the OS did a “open” for you on stdin, stdout, stderr when it created the process
How can you close a file descriptor?
close(filedescriptor)
Where do user processes reside in the address space?
In the User Mode Space
Does each process have access to the full address space?
Yes
What are the three steps to command piping?
- Create a pipe() (its kind of like a mailbox, shared among all processes)
- Fork the process
- Rewire the file descriptors
in process #0
close(1)
dup(f[1])
in process #1
close(0)
dup(f[0])
What’s the problem with redirecting the output of a process to the input of another process?
Processes are independent of each other, they can’t see each other’s data. That’s why we have to use the kernel space.
File descriptors
A array structure maintained by the kernel for each process.
Held in the kernel memory and process can modify them through syscall.
Each process has its own file descriptor.
Write system call function
write(1, str, strlen(str));