P2L4 Thread Design Considerations - Signals and Interrupts Flashcards

1
Q

What is an interrupt?

A
  • Interrupts are events to the CPU.
  • Interrupts are generated externally by components other than the CPU.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give 3 examples of components that can interrupt a CPU

A
  1. I/O devices
  2. Timers
  3. Other CPUs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a signal?

A

Signals are events that are:

  • Triggered by the CPU

​or

  • by software running on the CPU
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which particular interrupts can occur on a given physical platform depends on:

  1. the ___________ of that platform
  2. the ___________________ the platform comes with
  3. the _________________of the platform itself.
A
  1. the configuration of that platform
  2. the types of devices the platform comes with
  3. the hardware architecture of the platform itself.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do interrupts appear asynchronously or synchronously?

A

always asynchronously

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

Two identical hardware platforms, running different operating systems will have:

  • Same or different interrupts?
  • Same or different signals?
A

Same interrupts

Different signals

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

State 3 properties of signals that differ from interrupts

A
  1. notification from the CPU itself or from software running on the CPU
  2. which interrupts can occur depends on the operating system
  3. may be asynchonous or synchronous
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

State 3 properties of interrupts that are not shared with signals

A
  1. notification from outside the CPU, to the CPU
  2. which interrupts can occur on platform, depends on the physical platform (configuration, types of devices, hardware architecture)
  3. asynchonous
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List 3 similarities between interrupts and signals.

But for each similarity note the variation between interrupt and signal.

A
  1. unique identifier
    • interrupt —> defined by hardware
    • signal —> defined by OS
  2. can be masked (to enable/disable)
    • interrupt —> mask per-CPU
    • signal —> mask per process
  3. handler
    • interrupt —> handler specified for whole system
    • signal —> handler specified per process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give a toy shop visual metaphor for signals and interrupts.

  1. An interrupt is like ….
  2. A signal is like ….
  3. Discuss 3 ways of categorizing signals and interrupts
    1. ________________
    1. ________________
  • 3.__________________
A
  1. An interrupt is like … a snowstorm
  2. A signal is like …. a low battery warning
  3. Discuss 3 ways of categorizing signals and interrupts
    1. handle in specific ways, e.g. safety protocols, rules..
    1. Can be ignored (masking …)
  • 3.expected/unexpected - synchronous/asynchronous
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain how an interrupt works

A
  1. Device interrupts the CPU via the wires that connect it.
  2. It sends a unique message, i.e. INT-N.
  3. The hardware defined message is then looked up in a table
  4. Corresponding handler is called. (OS defined!!)
  5. The program counter is moved to that address of the handler code
  6. Handler routine is then executed.
  7. All of this happens within the context of the thread that is interrupted.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Interrupt handling always occurs outside of the thread context. True or false?

A

False

The interrupt interrupts the execution of the thread that was executing on top of the CPU

… The CPU looks up the interrupt number in a table, and executes the handler routine that the interrupt maps to …

All of this happens within the context of the thread that is interrupted.

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

What is SIGSEGV? It’s a signal that ….

Describe how it is handled as an example of signal handling

A

SIGSEGV - process tries to access memory that has not been allocated

Steps of signal handling:

  1. Signals originate from the CPU.
  2. For each process, the OS maintains a mapping
  3. Keys in map correspond to the signal number (SIGSEGV is signal 11, for example).
  4. Values in map point to the starting address of handling routines.
  5. When a signal is generated, the program counter is adjusted to point to the handling routine for that signal for that process.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give 3 examples of default actions the OS has for handling signals

A

The process may specify how a signal can handled, or the operating system default may be used. Some default signal responses include:

  • Terminate
  • Ignore
  • Terminate and Core Dump (like SIGSEGV)
  • Stop
  • Continue (from stopped)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give 2 examples of asynchronous signals and explain when they are sent.

A
  1. SIGKILL(kill) - from the point of view of targeted process, the kill comes asynchronously out of the blue!
  2. SIGALARM - timer timeout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give 3 examples of synchronous signals and explain when they are sent.

A
  1. SIGSEGV - access to protected memory
  2. SIGFPE - divide by zero
  3. SIGKILL(kill, id) - one process sends signal to kill another process
17
Q
  • Can a process install its own custom handling routine?
  • Can all signals be caught?
A
  • Yes, for most signals, processes can install its own custom handling routine, usually through a system call like signal() or sigaction()
  • No, there are some signals which cannot be caught.
18
Q

Why would you disable interrupts or signals? What problem could arise? How does disabling the interrupt/signal solve the problem?

A

Because a deadlock situation could arise.

Because interrupts and signals are handled in the same context of the thread being interrupted.

So there is a shared stack

So we need to use a mutex. But …

The interrupted thread is waiting for the handler to return. The handler is waiting for the interrupted thread to release the mutex lock —> deadlock!!

Solution:

  • disable the interrupt/signal before acquiring the mutex
  • re-enable interrupt/signal after releasing the mutex.

Once the signal is re-enabled, the pending signal is handled by the handler.

19
Q

Fill in the following with ‘interrupt’ or ‘signal’:

________ masks are maintained on a per CPU basis. This means that if a mask disables an ________ , the ________ ________ routing mechanism will not deliver the ________ to the CPU.

On the other hand, ________ masks are maintained on a per ________ ________ (_ _ _ on top of KLT). If a mask disables a ________ , the kernel will see this and will not interrupt the corresponding ________ ________ .

A

Interrupt masks are maintained on a per CPU basis. This means that if a mask disables an interrupt, the hardware interrupt routing mechanism will not deliver the interrupt to the CPU.

Signal masks are maintained on a per execution context (ULT on top of KLT). If a mask disables a signal, the kernel will see this and will not interrupt the corresponding execution context.

20
Q

True or False?

If the calling process defines a handler for a one-shot signal, each time the signal interrupts, that handler will be executed.

A

False

  • One-shot signals must also be explicitly re-enabled every time.
  • If the handler is not re-enabled, the default handler (if it exists) will be executed the subsequent times.
21
Q

One shot signals refer to …

Real time signals refer to …

A
  • One-shot signals refer to signals that will only interrupt once.
  • This means that from the perspective of the user level thread, n signals will look exactly like one signal.
  • One-shot signals must also be explicitly re-enabled every time.
  • Real Time Signals refer to signals that will interrupt as many times are they are raised.
  • If n signals occur, the handler will be called n times.
22
Q

When are these signals sent?

  1. SIGINT
  2. SIGURG
  3. SIGTTOU
  4. SIGXFSZ
A
  1. terminal interrupt signal
  2. high bandwidth data is available on a socket
  3. background process attempting to write.
  4. file size limit exceeded