OS Topic 11 - Context Switching Flashcards

1
Q

Process states

You have seen that an operating system appears to allow many processes to run concurrently, but that in reality it is rapidly s_________ execution among processes.

A

switching

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

Process states

In order to perform process switching, the operating system has to keep track of which processes currently exist and which are ready to run.

For each process, the operating system maintains a record called a c_______ b____ which contains relevant information about the process, such as which areas of memory are allocated to it.

A

context block

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

Process states

The context block also records the state of the process.

Give an example of one such state.

A

E.g. Whether the process is running or not.

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

Process states

If a process initiates an I/O operation what does the operating system typically do?

A

It suspends the process until the I/O operation completes.

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

Process states

Why does the OS suspend a process that has initiated an I/O operation until after the operation completes?

A

Because I/O operations take a much longer time than the main processer, if it were to wait it could be idle for some time.

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

Process states

A suspended process is said to be ‘b_________’.

A

blocked

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

Process states

Once an OS has suspended a process until it has completed it’s I/O operation, what might it do?

A

Allow another process to be executed.

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

Process states

In ‘state diagrams’ which shapes are used to represent states?

A

Ovals

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

Process states

In ‘state diagrams’ which shapes are used to represent transitions between states?

A

Arrows

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

Process states

What happens when the I/O operation completes?

The process that was blocked is no longer blocked and the operating system must update its s_______ to show this.

A

state

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

Process states

Once a process has been unblocked the OS can either update its state to r__________, or
to r_________.

A

running
ready

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

Process states

Suppose a process starts a lengthy calculation without performing any I/O. If it were to continue to be executed, then it would stop any other processes from being executed. How could the operating system prevent this?

A

By limiting the maximum amount of time for which a process can run:

it may allow, say, 10 ms. At the end of this time slice or quantum, the operating system will suspend the running process and pick another process to be executed.

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

Process states

Given that only one process can run at any one time on a single processor, how is it possible for the OS to run a process in order to interrupt a process?

There are two solutions:

  1. c_____________ multitasking
  2. p_____________ multitasking.
A

cooperative multitasking
pre-emptive multitasking

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

Process states

Cooperative multitasking is a solution whereby all application programs are written so that they p_____________ yield control back to the operating system.

The operating system then gets a chance to decide which process should run next.

A

periodically

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

Process states

There are problems with cooperative multitasking: programmers may be tempted to gain extra performance for their application by _____________________________________________

A worse problem is a program containing a bug that results in an endless loop.
It would never _____________________________________________

A

by breaking the rules and not yielding control

yield control and so could crash the entire machine.

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

Process states

Pre-emptive multitasking is an alternative solution. It is a way in which the operating system can always pre-empt an executing process and take control of the processor at any time.

It uses a h____________ i_____________ to do this.

A

A hardware interrupt

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

Process states

Hardware interrupts

An OS will set a timer to generate r________ i___________ that will interrupt any running process.

A

regular interrupts

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

Process states

True or false?
A pre-emptive system may also allow a process to yield control voluntarily.

A

True

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

Context switching

Multitasking depends on r________ s_________ between running processes. Changing which process is c_________ executing is known as context switching;

A

rapid switching
currently

20
Q

Context switching

There are three problems the OS designer must solve, which essentially address the w______, w______ and h_____ of context switching.

A

when, what, how

21
Q

Context switching

‘When’
The first is to ensure that the OS itself is e_________ when a context switch is required.

A

executing

22
Q

Context switching

‘What’
The second is what information about a process must be s_______ so that it can be stopped and restarted.

A

saved

23
Q

Context switching

‘How’
The third is how to c_________ switch the processor from executing one process to executing another.

A

cleanly switch

24
Q

Context switching

True or false?
‘State’ transition only happen when a process is blocked.

True or false?
‘State’ transitions are handled by the operating system.

A

False
State transitions only happen during a system call or an interrupt.

True

25
Q

Context switching

What mode will the processor be in while a context switch occurs?

A

kernel mode

Kernel mode is essential for privileged instructions and ensures that only the OS can access key data structures such as the context blocks

26
Q

Context switching

In the context of context switching, what does “IP” typically refers to?

A

Instruction Pointer

27
Q

Context switching

The Instruction Pointer is a r______ in a computer’s central processing unit (CPU) that points to the memory address of the next instruction to be executed.

A

register

28
Q

Context switching

What is a register?

In computer architecture, a register is a small, fast s_______ l_________ within the CPU (Central Processing Unit).

A

storage locations

29
Q

Context switching

What are registers used for?

Registers are used to quickly s______ and r_______ data. Registers are part of the CPU’s control unit.

A

store and retrieve

30
Q

Context switching

True or false?

Registers play a crucial role in the execution of machine instructions.

A

true

31
Q

Context switching

Processes and threads

True or false?
A context switch between the threads of one program is easier and quicker than a context switch between different processes?

A

True

32
Q

Coordinating concurrent processes

Multiple concurrent processes and threads can also be used to collaborate on tasks, for example a background spell check can run while ____________________________

A

I type something in the word processor.

33
Q

Coordinating concurrent processes

One issue that arises when considering collaborating processes is whether m________ can be shared between processes.

What alternative, that can already share memory, can be used?

A

memory

An OS normally provides separate memory space for each full process for privacy and security, so additional features must be provided to allow memory sharing in a controlled manner.

threads

34
Q

Coordinating concurrent processes

Instead of shared memory, an OS can provide other mechanisms to allow separate processes to communicate with each other, for example by passing m________ from one process to another via the operating system.

A

messages

35
Q

Coordinating concurrent processes

There are some problems that arise when writing programs that r______ on concurrent processes.

A

rely

36
Q

Coordinating concurrent processes (a race condition)

A race condition in programming occurs when the outcome of a program depends on the timing of events, particularly when multiple parts of the program are trying to do things at the same time. It’s like a “race” between different parts of the program, and the result can be u__________ and i__________ if not managed properly.

A

unpredictable
incorrect

Remember the bank deposit withdrawal and deposit on the module website.

37
Q

Coordinating concurrent processes (a race condition)

There are particular portions of the code, known as c______ r_________, where problems can arise; there may be other areas of code that cause no concurrency problems.

A

critical regions

38
Q

Coordinating concurrent processes (a race condition)

True or False
Third, problems only arise if concurrent processes execute critical regions for a shared resource.

A

true

39
Q

Coordinating concurrent processes (a race condition)

True or false?
Code doesn’t have to be perfect. It is okay if code is not written to operate correctly in all circumstances.

A

False

Code must be written to operate correctly in all circumstances.

40
Q

Coordinating concurrent processes (a race condition)

Code must be written to operate correctly in all circumstances. This means identifying s_______ r_________ and critical regions of code and using techniques such as the s__________.

A

shared resources
critical regions
semaphore

41
Q

Coordinating concurrent processes (a race condition)

What is the semaphore technique?
A semaphore can lock a critical region so that only a s_________ process can execute at a time.

If critical regions are correctly identified, and c______________ avoided in these regions, then correctness can be guaranteed and race conditions, for example, cannot occur.

A

single
concurrency

42
Q

Semaphores

A simple metaphor for a semaphore is: a barrier that controls access to a car park. If the barrier is up, then a car can enter; but if it is down, then the car must wait. When a car leaves, the barrier is raised, allowing any waiting car to enter.

Which integer 1 or 0 is used to show that the barrier is raised?

A

1 for raised
0 for down

43
Q

Semaphores

Using a semaphore requires two system calls:

sem_wait if the semaphore count is 0, then the process w______; if not 0, then the count is decremented and the process continues
sem_signal i___________ the count, releasing another process if one is waiting.

A

waits
increments

44
Q

Semaphores

There are also system calls needed to c________ and d__________ semaphores so that different semaphores can be used for different applications.

A

create and destroy

45
Q

Semaphores

A semaphore used for ‘m______ e_________’ helps to enforce a rule where only one thread or process is allowed to access a specific section of code or resource at any given moment.

A

mutual exclusion

46
Q

Semaphores

A semaphore used in this way for mutual exclusion is often referred to as a m_________

A

mutex

47
Q
A