Lecture 4: Process / Shell (Part 2) Flashcards

1
Q

When a fork() occurs, what is copied?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When is it considered to be better to open files: before a fork() or after a fork()?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When a pipe is created via “int pipe(int fields[2])”, what is used for reading and writing?

A

filedes[0] is used for reading

filedes[1] is used for writing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Be default: if a writing process attempts to write to a full pipe, what happens?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

By default: if a read process attempts to read from an empty pipe, what happens?

A

System will automatically block the read until there is data to read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the dup() function do?

A

It re-routes input and/or output to a user-specified destination. This function is critical to utilizing pipes properly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly