Lecture 4: Process / Shell (Part 2) Flashcards
When a fork() occurs, what is copied?
Everything about the original process including:
- current line of code program is at
- copy of all variables and their values
- the process’s file descriptor table where whatever its entries are pointing at will be pointing to the same entries
When is it considered to be better to open files: before a fork() or after a fork()?
After a fork() because then the child’s file will then get its own entry in the System File Descriptor table and behaviour with this file will not affect the parent’s file
When a pipe is created via “int pipe(int fields[2])”, what is used for reading and writing?
filedes[0] is used for reading
filedes[1] is used for writing
Be default: if a writing process attempts to write to a full pipe, what happens?
System will automatically block the write until there is space. The OS has a limit on the buffer space used by the pipe. If you hit the limit, the write will block.
By default: if a read process attempts to read from an empty pipe, what happens?
System will automatically block the read until there is data to read.
What does the dup() function do?
It re-routes input and/or output to a user-specified destination. This function is critical to utilizing pipes properly.