6. Interrupt and Exception Handling Flashcards

1
Q

What is the most challenging part of implementing exec()?

A

Ensuring that, on failure, exec() can return to the calling process.

Specifically, we do not want to make any changes to the process’ address space until we are sure that things will succeed.

Solution: Prepare a separate address space and swap it in when everything is set appropriately.

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

Describe how a process dies.

A

Processes choose the moment of their own end by calling end() with an exit code.

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

What does wait() do?

A

The parent process calls wait() to retrieve the exit code of a specified child process.

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

What is a zombie thread/process?

A

A thread/process which has exited, but its parent process (or init) has not called wait() to retrieve its exit code yet. The mapping of PID to exit code occupies memory until wait() is called.

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

What happens if a process’s parent exits before it (the child) does?

A

The “orphaned” process is assigned the init process as a parent, which will collect its exit code when it exits. This is called reparenting.

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

How do we prevent zombies from taking over the machine?

A

A process’s parent receives the SIGCHILD signal when a child calls exit(), alerting it to the chance to retrieve the child’s exit status.

On some systems a process can choose to have its children automatically reaped by ignoring this signal.

On bash the relevant command is the appropriately-named disown. This allows children to continue running as daemons even after bash exits.

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

What is a blocking wait()?

A

Will block until the child exits, unless it has already exited, in which case it returns immediately

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

What is a non-blocking wait()?

A

Will not block. Instead, it returns status indicates if the child has exited and, if so, what the exit code was.

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

What is the difference between an errno and the return code of a syscall?

A

System calls have return code that matter in the kernel. The C library has wrappers that call the syscall and change the return codes to an errno that is meaningful in C.

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

What are the limitations or problems with the hardware resource that the operating system is trying to address?

A

There is only one (or at least, not that many) processor(s)

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

What are the mechanisms necessary to allow the processor to be shared?

A

Interrupts and context switching.

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

What do programmers achieve through processor multiplexing?

A

Concurrency (good) and synchronization (something that has to be done to safely multiplex).

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

How do we design good policies ensuring that processor sharing meets the needs of the user?

A

Processor scheduling.

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

Why does the operating system need special privileges (that user programs cannot have)?

A

In order to divide resources between processes the system needs a TRUSTED and privileged entity that can divide the resources and enforce the division. Remember that user programs can be buggy or malicious, so the rule is to never trust user processes to handle hardware multiplexing.

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

Why can’t processes share resources without a privileged arbiter?

A

Some processes are malicious (Steal memory from another process. Or do bad things with the system).

Some processes are buggy (Accessing memory from other processes accidentally because of bad code)

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

What privileges does the CPU get in kernel (privileged) mode?

A

The executing code has access to special instructions and has a different view of memory.

17
Q

What can the “special instructions” available in kernel mode do?

A

They usually modify important global state, controlling how resources are shared.

(Note: if not in kernel mode, trying to use these instructions usually forces the kernel to kill the guilty process)

18
Q

What are protection boundaries and what is their purpose?

A

The CPU implements mechanisms to transition between user and kernel mode alongside requiring that only trusted kernel code runs in kernel mode.

[Insert more here]

19
Q

What do we mean when we refer to code as an “application”?

A

Code running without privileges or in unprivileged “user” mode

20
Q

What do we mean when we refer to code as the “kernel”?

A

Code running in privileged or kernel mode.

21
Q

What makes the kernel special?

A

It is the one application allowed to execute code in kernel mode.

22
Q

Why is the operating system allowed to run in kernel mode?

A

This is what it means to install an operating system: choose a particular application to grant special privileges to (it better be a good, non-buggy one).

On boot the CPU starts executing kernel code in privileged mode, and it is the kernel’s responsibility for lowering the privilege level before executing user code.

23
Q

What does it mean to “trap” into the kernel?

A

When a normal application does something that causes the system to enter kernel mode. One way to think about it is to imagine the user thread running inside of the kernel after the trap occurs.

24
Q

What are the three reasons why the thread of execution enters into privileged (kernel) mode?

A
  1. A hardware device requires attention (hardware interrupt).
  2. Software requests attention (software interrupt/system call).
  3. Software NEEDS attention (software exception)
25
Q

What are hardware interrupts used for?

A

To signal that a particular device needs attention.

Ex: disk read is complete, network packet was received, a timer fired

26
Q

What is an interrupt line?

A

Input wires on which a logic transition (or level) will trigger an interrupt

27
Q

What three things happen with the processor when an interrupt is triggered?

A
  1. The process enters privileged mode (traps into the kernel).
  2. The processor records the state (?) necessary to process the interrupt. 3. Jumps to a pre-determined memory location and begins executing instructions.
28
Q

What is the interrupt service routine (ISR)?

A

The instructions that the processor executes when an interrupt fires