Topic 11 – Context switching Flashcards

1
Q

in regards to the context block:

this is a record of what state the process is in such as running, ready or blocked, it is used to decide how the process should be treated.

A

in regards to the context block what is the:

process state

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

in 7 steps describe how

buffer control is possible by using a semaphore

A

the steps that describe this are:

  1. a buffer is empty and has a size of 10 (the semaphore value is 10)
  2. a process wishes to deposit an item so makes a SEM_WAIT system call
  3. since the semaphore is not 0 the process can deposit the item in the buffer
  4. the semaphore value is now decremented to 9
  5. steps 2 - 5 will reapeat untill the semaphore reaches 0
  6. a process wishes to deposit an item so makes a SEM_WAIT system call
  7. the semaphor count is 0 and so the process is put into a waiting state until another process removes an item from the buffer and makes the system call SEM_SIGNAL so that the semaphore can be incremented by 1

note

this example does not take into account an event such as two threads colliding at a buffer address (race condition) for this to be mitigated a seperate semaphore would be needed for mutual exclusion (mutex)

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

the main feature of the processor that the operating system takes advantage of to achieve this is:

the fact that a hardware interrupt will pause the execution of any process then switch to kernel mode and hand control of the CPU to the operating system

the hardware interrupt in question is received from a hardware timer

A

what is the main feature of the processor that the operating system takes advantage of to achieve

pre-emptive multitasking

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

describe in 5 steps the

stack pointer

during an interrupt without a context switch

A

this without a context switch

  1. an interrupt occurs
  2. process A instruction pointer is placed on top the stack pointer
  3. the routine is placed inside the instruction pointer and is executed
  4. when the routine is finished it will call the RETURN instruction
  5. process A instruction pointer is pulled of the stack pointer and execution commences where it was paused
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

in regards to the context block:

this records information such as a processes running time (quantum) and other information that can be used by the scheduler so that it can decide the order of execution

A

in regards to the context block what is the:

process priority

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

what are the two actions that can occur that would

cause a process to be transitioned and control of the CPU handed back to the operating system

A

these actions include:

  1. Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
  2. Transition because of an interrupt: for example when the hardware timer interrupts

For either of these the process will change state and the OS will handle the events

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

two use cases of this are:

  1. mutual exclusion (mutex) - this can be used by a thread to tell other threads that it is currently executing a critical region of code and that the resource must not be acceessed this avoids scenerios such as a race condition
  2. buffer control - this can also be used as a counter for example how many units are available in a buffer
A

name 2 uses of the

semaphore

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

name 6 pieces of information that would be found in the

context block

for a process

A

this would record details for a process such as:

  • Process Identifier (PID)
  • the process state
  • the process priority
  • saved register contents
  • information about the processes memory space
  • information about files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

while the processor is in kernel mode what 2 items does the operating system have access to

A

while the processor is in this mode the opearting system can access:

  • all instructions including privileged instructions
  • all data structures including the context block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

in summary these problems occure when:

  1. There is a shared resource
  2. There are critical regions of code acting on those shared resources
A

in two summary points when do Concurrency problems such as the race condition occur

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

this system call essentially asks the OS if it can enter a critical region of code. If the semaphore count is 0 then the process is placed into a waiting state. If the semaphore count is not 0 then the semaphore count is set to 0 and the process enters a critical region of code

A

describe the semaphore system call

SEM_WAIT

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

with this type of state the operating system knows that the process is currently using the CPU

A

if a

process is in a running state

what does the operating system know about the process

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

these actions include:

  1. Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
  2. Transition because of an interrupt: for example when the hardware timer interrupts

For either of these the process will change state and the OS will handle the events

A

what are the two actions that can occur that would

cause a process to be transitioned and control of the CPU handed back to the operating system

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

this would record details for a process such as:

  • Process Identifier (PID)
  • the process state
  • the process priority
  • saved register contents
  • information about the processes memory space
  • information about files
A

name 6 pieces of information that would be found in the

context block

for a process

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

if a process is in this state then the operating system knows that it is waiting on an I/O operation to complete

A

if a

process is in a blocked state

what does the operating system know about the process

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

this can only occur after a system call has been made or a hardware interrupt signal has been received.

in either case the processor will switch to kernel mode and the OS will gain control of the CPU, allowing it a chance to check the quantum of any running processes and run its scheduler if any quantum has expired

A

when can context switching occur

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

describe the semaphore system call

SEM_SIGNAL

A

this system call essentially tells the operating system that it is finished executing its critical region of code and the semaphore count can be incremented so that another process may enter its critical region of code.

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

this is a place in the source code that acts on a shared resource. If these actions are not carried out correctly and in full then the value of the shared resource could become false

A

what is a

critical region

of code

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

this is a solution to multitasking

within this solution the operating system has control over when it will use the CPU.

it does this by setting a hardware timer that will interrupt any process

A

describe what

pre-emptive multitasking

is

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

this is the term given to a semaphore when it is used for the purpose of mutual exclusion

note

semaphores have many use cases within the operating system

A

what is a

mutex

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

in regards to the context block what is the:

process priority

A

in regards to the context block:

this records information such as a processes running time (quantum) and other information that can be used by the scheduler so that it can decide the order of execution

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

this is the act of the currently running process being replaced by another process

note

since all data within the CPU registers will be replaced it is said that the CPU is now executing in a different “context”

A

what is

context switching

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

if a

process is in a ready state

what does the operating system know about the process

A

if a process is in this state then the operating system knows that it is waiting to be rescheduled to use the CPU

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

execpt for the semaphore system calls SEM_WAIT and SEM_SIGNAL

what other system calls are there that are associatied with the semaphore

A

There are also system calls that allow the creation and destroying of different semaphores so that different semaphores can be used by different applications

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

this is a diagram that expresses the transition and states of a process.

  • ovals show the state of a process
  • arrows show the direction and transition of a process from one state to another

notes

  • All states and transitions should be labelled with there appropriate state or transition.
  • These are important for design as well as understanding
A

describe a

state diagram and its components

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

in regards to the context block what is the:

Information about the process’s memory space

A

in regards to the context block:

this is information about what memory the process has allocated to it.

information recorded would include the address range of the memory

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

the steps include:

  1. Process A running
  2. Process A makes SEM_WAIT system call
  3. Semaphore count is 0
  4. Process A placed in waiting state
  5. Process B makes SEM_SIGNAL system call
  6. Semaphore count is incremented by 1
  7. Process A state changed from waiting to ready
  8. Semaphore count set to 0
  9. Process A is rescheduled and runs its critical code
  10. Process A finishes and makes SEM_SIGNAL system call
  11. Semaphore count is incremented by 1

If step 3 had a count of 1 then execution would jump to step 8

A

describe in 11 steps what happens when:

  1. process B is running critical code on a resource
  2. process A tries to access the same resource

and a mutex is in use by both processes

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

this works in the following steps:

  1. the opearating system has control of the CPU
  2. it will set a hardware timer
  3. a new process is scheduled to use the CPU
  4. the hardware timer sends a hardware interrupt signal to the processor
  5. the processor switches to kernel mode and the interrupt service routine for the timer is executed on the CPU
  6. since the interrupt service routine for the timer is part of the operating system it can call on the scheduler if any process in a running state has quantum that has expired
A

describe how

pre-emptive multitasking

works in 6 steps

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

two purposes of this are:

  1. for use by the scheduler - so that it can determine which process should be executed next
  2. for use during a context switch - so that a state of a process can be restored or saved (such as the state of registers or the memory a process has allocated to it)
A

name 2 purposes for the

context block

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

name 1 benefit and disadvantage of

pre-emptive multitasking

A

a benefit of this is:

If code is buggy or malicious then the operating system will always be able to regain control of the CPU

a disadvantage of this is:

that a process could be interrupted at a critical point in its execution and data could be left inconsistent. this is especially true of concurrent processes that are sharing data (race condition)

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

describe in 8 steps the

stack pointer

during an interrupt with a context switch

A

this with a context switch

  1. an interrupt occurs
  2. process A has its instruction pointer placed on top the stack pointer
  3. the routine is placed inside the instruction pointer and executed
  4. the routine detects that process A has expired quantum and the OS scheduler is called
  5. the operating system must make a context switch from process A to process B
  6. the stack pointer register has its contents changed, now the stack pointer holds process B stack pointer
  7. the routine finishes execution and calls the RETURN instruction
  8. process B instruction pointer is pulled of the stack pointer and into the instruction pointer and execution commences where it was paused
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

this is a phenomenon that occurs when two or more concurrent threads are sharing a resource

its a problem that lies where they both are carrying out tasks on that resource but neither has finished its task fully

the outcome is that depending on the order of who fnishes arrying out the task on that resource determines the final value of that resource

the final value of the resource will most likely be incorrect

A

describe what the

race condition

is

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

if a process is in this state then the operating system knows that it is waiting to be rescheduled to use the CPU

A

if a

process is in a ready state

what does the operating system know about the process

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

outline the state of a process and any transitions for the following sceneraio

a process makes an I/O system call where it will be blocked and then rescheduled

A

for this scenerio the steps are as follows:

  1. the process A is in a running state
  2. the process A makes an I/O system call to the operating system
  3. processor mode switches to kernel mode
  4. the operating system foresees the I/O operation taking some time
  5. the process A is placed in a blocked state
  6. a context switch occurs and another process is given control of the processor
  7. processor mode switches to user mode
  8. a hardware interrupt is received by the processor from the I/O device telling the processor that it is ready
  9. processor mode switches to kernel mode
  10. context switch occurs and the interrupt service routine for the I/O device is executed
  11. the process A is unblocked and placed into a ready state until it is rescheduled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

what is a

semaphore

A

this is a service that is built into the operating system.

this enables the control and access of a shared resource so that threads sharing such a resource can avoid errors such as a race condition

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

what is

context switching

A

this is the act of the currently running process being replaced by another process

note

since all data within the CPU registers will be replaced it is said that the CPU is now executing in a different “context”

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

these signals are sent to the processor by an I/O device. telling the processor that it is ready to either send or recieve data

A

when are

hardware interrupt signals

sent to the processor

38
Q

name 2 uses of the

semaphore

A

two use cases of this are:

  1. mutual exclusion (mutex) - this can be used by a thread to tell other threads that it is currently executing a critical region of code and that the resource must not be acceessed this avoids scenerios such as a race condition
  2. buffer control - this can also be used as a counter for example how many units are available in a buffer
39
Q

the operating system stores these inside of main memory and they are updated for each process whenever it makes a transition from a running state to any non running state

A

where does the

operating sytem store each context block for a process and when does each get updated

40
Q

this without a context switch

  1. an interrupt occurs
  2. process A instruction pointer is placed on top the stack pointer
  3. the routine is placed inside the instruction pointer and is executed
  4. when the routine is finished it will call the RETURN instruction
  5. process A instruction pointer is pulled of the stack pointer and execution commences where it was paused
A

describe in 5 steps the

stack pointer

during an interrupt without a context switch

41
Q

methods that will accomplish this are:

  • Cooperative multitasking
  • Pre-emptive multitasking
A

what are 2 methods that

ensure that the operating system can always gain back control of a processor so that it can carry out its own tasks such as scheduling

42
Q

where does the

operating sytem store each context block for a process and when does each get updated

A

the operating system stores these inside of main memory and they are updated for each process whenever it makes a transition from a running state to any non running state

43
Q

this with a context switch

  1. an interrupt occurs
  2. process A has its instruction pointer placed on top the stack pointer
  3. the routine is placed inside the instruction pointer and executed
  4. the routine detects that process A has expired quantum and the OS scheduler is called
  5. the operating system must make a context switch from process A to process B
  6. the stack pointer register has its contents changed, now the stack pointer holds process B stack pointer
  7. the routine finishes execution and calls the RETURN instruction
  8. process B instruction pointer is pulled of the stack pointer and into the instruction pointer and execution commences where it was paused
A

describe in 8 steps the

stack pointer

during an interrupt with a context switch

44
Q

in regards to the context block:

this is information about what memory the process has allocated to it.

information recorded would include the address range of the memory

A

in regards to the context block what is the:

Information about the process’s memory space

45
Q

in 4 points how can a

race condition be avoided

A

this can be avoided by:

  • identifiying shared resources
  • identifying critical code using those shared resources
  • employing methods that allow a thread to execute its critical code without being distured (semaphore)
  • employ methods that allow a thread exclusive access to a shared resource while it is carrying out critical code (semaphore)
46
Q

in regards to the context block what is the:

process state

A

in regards to the context block:

this is a record of what state the process is in such as running, ready or blocked, it is used to decide how the process should be treated.

47
Q

what are 2 methods that

ensure that the operating system can always gain back control of a processor so that it can carry out its own tasks such as scheduling

A

methods that will accomplish this are:

  • Cooperative multitasking
  • Pre-emptive multitasking
48
Q

in the context of a race condition this can ensure that:

only one thread can be executing critical code on a shared resource at a time

this guarantees that a race condition cannot occur

A

in the context of a race condition what can a

semaphore ensure

49
Q

in regards to the context block:

this is a record of any open files that a process may have open and that the operating system needs to keep track of

A

in regards to the context block what is the:

Information about files

50
Q

in regards to the context block:

this uniquely identifies a process

A

in regards to the context block what is the

Process Identifier (PID)

51
Q

what are 3 problems that arise from

context switching

which must always be solved to enable multitasking

A

3 problems that arise from this are:

  • The first is to ensure that the OS itself is executing when a context switch is required
  • second is what information about a process must be saved so that it can be stopped and restarted
  • third is how to cleanly switch the processor from executing one process to executing another
52
Q

when are

hardware interrupt signals

sent to the processor

A

these signals are sent to the processor by an I/O device. telling the processor that it is ready to either send or recieve data

53
Q

this is a service that is built into the operating system.

this enables the control and access of a shared resource so that threads sharing such a resource can avoid errors such as a race condition

A

what is a

semaphore

54
Q

There are also system calls that allow the creation and destroying of different semaphores so that different semaphores can be used by different applications

A

execpt for the semaphore system calls SEM_WAIT and SEM_SIGNAL

what other system calls are there that are associatied with the semaphore

55
Q

if a

process is in a blocked state

what does the operating system know about the process

A

if a process is in this state then the operating system knows that it is waiting on an I/O operation to complete

56
Q

name 2

disadvantages of Cooperative multitasking

A

disadvantages of this include:

  1. process hogging - programmers could choose to hold on to the CPU for longer than they should so that they can gain extra performance at the benefit of other processes
  2. buggy programs - A buggy application that never reaches a point where control would be yielded back to the operating system such as being stuck in a loop. would potentially mean that the system would crash since the operating system cannot regain control of the CPU and make any recoveries
57
Q

in regards to the context block:

this is the contents of the CPU registers that was stored for the process when a context switch occured

saved data would include:

  • stack pointer register
  • instruction pointer register
  • status register
A

in regards to the context block what is the:

saved register contents

58
Q

give an example of a race condition where the shared resource is a bank balance and thread A is depositing 100 and thread B is withdrawing 100

A

an example of this would be:

  1. thread A reads the bank balance at 500
  2. a context switch occurs
  3. thread B raeds the banks balance at 500
  4. a context switch occurs
  5. thread A adds 100 to the 500 and updates the balance to 600
  6. a context switch occurs
  7. thread B subtracts 100 from the 500 and updates the balance to 400

the final balance is 400 when it should still be 500. this occured because thread A could not finish its critical code before the context switch

59
Q

this can be avoided by:

  • identifiying shared resources
  • identifying critical code using those shared resources
  • employing methods that allow a thread to execute its critical code without being distured (semaphore)
  • employ methods that allow a thread exclusive access to a shared resource while it is carrying out critical code (semaphore)
A

in 4 points how can a

race condition be avoided

60
Q

describe what

Cooperative multitasking

is

A

this is a solution that enables multitasking

it involves all application programs to be written in such a way that they will periodically yield control of the CPU back to the operating system so that it can be rescheduled and other processes can use the CPU.

61
Q

how many processors are operating systems designed to run on

A

these are designed to run on one processor.

they are software just like any application program and must share control of the resources available.

the crucial difference is that this has the responsibility to orchestrate the use of resources correctly and efficiently

62
Q

in regards to the context block what is the:

Information about files

A

in regards to the context block:

this is a record of any open files that a process may have open and that the operating system needs to keep track of

63
Q

when can context switching occur

A

this can only occur after a system call has been made or a hardware interrupt signal has been received.

in either case the processor will switch to kernel mode and the OS will gain control of the CPU, allowing it a chance to check the quantum of any running processes and run its scheduler if any quantum has expired

64
Q

in regards to the context block what is the

Process Identifier (PID)

A

in regards to the context block:

this uniquely identifies a process

65
Q

3 problems that arise from this are:

  • The first is to ensure that the OS itself is executing when a context switch is required
  • second is what information about a process must be saved so that it can be stopped and restarted
  • third is how to cleanly switch the processor from executing one process to executing another
A

what are 3 problems that arise from

context switching

which must always be solved to enable multitasking

66
Q

what is a

critical region

of code

A

this is a place in the source code that acts on a shared resource. If these actions are not carried out correctly and in full then the value of the shared resource could become false

67
Q

disadvantages of this include:

  1. process hogging - programmers could choose to hold on to the CPU for longer than they should so that they can gain extra performance at the benefit of other processes
  2. buggy programs - A buggy application that never reaches a point where control would be yielded back to the operating system such as being stuck in a loop. would potentially mean that the system would crash since the operating system cannot regain control of the CPU and make any recoveries
A

name 2

disadvantages of Cooperative multitasking

68
Q

what is the main feature of the processor that the operating system takes advantage of to achieve

pre-emptive multitasking

A

the main feature of the processor that the operating system takes advantage of to achieve this is:

the fact that a hardware interrupt will pause the execution of any process then switch to kernel mode and hand control of the CPU to the operating system

the hardware interrupt in question is received from a hardware timer

69
Q

describe the semaphore system call

SEM_WAIT

A

this system call essentially asks the OS if it can enter a critical region of code. If the semaphore count is 0 then the process is placed into a waiting state. If the semaphore count is not 0 then the semaphore count is set to 0 and the process enters a critical region of code

70
Q

the steps that describe this are:

  1. a buffer is empty and has a size of 10 (the semaphore value is 10)
  2. a process wishes to deposit an item so makes a SEM_WAIT system call
  3. since the semaphore is not 0 the process can deposit the item in the buffer
  4. the semaphore value is now decremented to 9
  5. steps 2 - 5 will reapeat untill the semaphore reaches 0
  6. a process wishes to deposit an item so makes a SEM_WAIT system call
  7. the semaphor count is 0 and so the process is put into a waiting state until another process removes an item from the buffer and makes the system call SEM_SIGNAL so that the semaphore can be incremented by 1

note

this example does not take into account an event such as two threads colliding at a buffer address (race condition) for this to be mitigated a seperate semaphore would be needed for mutual exclusion (mutex)

A

in 7 steps describe how

buffer control is possible by using a semaphore

71
Q

This is a snapshot or a record of every process and its state that must be known about by the operating system

A

what is the

context block

72
Q

while the processor is in this mode the opearting system can access:

  • all instructions including privileged instructions
  • all data structures including the context block
A

while the processor is in kernel mode what 2 items does the operating system have access to

73
Q

name 2 purposes for the

context block

A

two purposes of this are:

  1. for use by the scheduler - so that it can determine which process should be executed next
  2. for use during a context switch - so that a state of a process can be restored or saved (such as the state of registers or the memory a process has allocated to it)
74
Q

this is a solution that enables multitasking

it involves all application programs to be written in such a way that they will periodically yield control of the CPU back to the operating system so that it can be rescheduled and other processes can use the CPU.

A

describe what

Cooperative multitasking

is

75
Q

in two summary points when do Concurrency problems such as the race condition occur

A

in summary these problems occure when:

  1. There is a shared resource
  2. There are critical regions of code acting on those shared resources
76
Q

what is the

context block

A

This is a snapshot or a record of every process and its state that must be known about by the operating system

77
Q

these are designed to run on one processor.

they are software just like any application program and must share control of the resources available.

the crucial difference is that this has the responsibility to orchestrate the use of resources correctly and efficiently

A

how many processors are operating systems designed to run on

78
Q

describe how

pre-emptive multitasking

works in 6 steps

A

this works in the following steps:

  1. the opearating system has control of the CPU
  2. it will set a hardware timer
  3. a new process is scheduled to use the CPU
  4. the hardware timer sends a hardware interrupt signal to the processor
  5. the processor switches to kernel mode and the interrupt service routine for the timer is executed on the CPU
  6. since the interrupt service routine for the timer is part of the operating system it can call on the scheduler if any process in a running state has quantum that has expired
79
Q

an example of this would be:

  1. thread A reads the bank balance at 500
  2. a context switch occurs
  3. thread B raeds the banks balance at 500
  4. a context switch occurs
  5. thread A adds 100 to the 500 and updates the balance to 600
  6. a context switch occurs
  7. thread B subtracts 100 from the 500 and updates the balance to 400

the final balance is 400 when it should still be 500. this occured because thread A could not finish its critical code before the context switch

A

give an example of a race condition where the shared resource is a bank balance and thread A is depositing 100 and thread B is withdrawing 100

80
Q

if a

process is in a running state

what does the operating system know about the process

A

with this type of state the operating system knows that the process is currently using the CPU

81
Q

in regards to the context block what is the:

saved register contents

A

in regards to the context block:

this is the contents of the CPU registers that was stored for the process when a context switch occured

saved data would include:

  • stack pointer register
  • instruction pointer register
  • status register
82
Q

what is a

mutex

A

this is the term given to a semaphore when it is used for the purpose of mutual exclusion

note

semaphores have many use cases within the operating system

83
Q

for this scenerio the steps are as follows:

  1. the process A is in a running state
  2. the process A makes an I/O system call to the operating system
  3. processor mode switches to kernel mode
  4. the operating system foresees the I/O operation taking some time
  5. the process A is placed in a blocked state
  6. a context switch occurs and another process is given control of the processor
  7. processor mode switches to user mode
  8. a hardware interrupt is received by the processor from the I/O device telling the processor that it is ready
  9. processor mode switches to kernel mode
  10. context switch occurs and the interrupt service routine for the I/O device is executed
  11. the process A is unblocked and placed into a ready state until it is rescheduled
A

outline the state of a process and any transitions for the following sceneraio

a process makes an I/O system call where it will be blocked and then rescheduled

84
Q

this system call essentially tells the operating system that it is finished executing its critical region of code and the semaphore count can be incremented so that another process may enter its critical region of code.

A

describe the semaphore system call

SEM_SIGNAL

85
Q

in this case it can guarantee mutual exclusion that is that only one process can be executing a critical region of code at the same time.

this in turn can mitigate a race problem

A

when two values are being used for a semaphore

what can the semaphore guarantee

86
Q

a benefit of this is:

If code is buggy or malicious then the operating system will always be able to regain control of the CPU

a disadvantage of this is:

that a process could be interrupted at a critical point in its execution and data could be left inconsistent. this is especially true of concurrent processes that are sharing data (race condition)

A

name 1 benefit and disadvantage of

pre-emptive multitasking

87
Q

describe in 11 steps what happens when:

  1. process B is running critical code on a resource
  2. process A tries to access the same resource

and a mutex is in use by both processes

A

the steps include:

  1. Process A running
  2. Process A makes SEM_WAIT system call
  3. Semaphore count is 0
  4. Process A placed in waiting state
  5. Process B makes SEM_SIGNAL system call
  6. Semaphore count is incremented by 1
  7. Process A state changed from waiting to ready
  8. Semaphore count set to 0
  9. Process A is rescheduled and runs its critical code
  10. Process A finishes and makes SEM_SIGNAL system call
  11. Semaphore count is incremented by 1

If step 3 had a count of 1 then execution would jump to step 8

88
Q

in the context of a race condition what can a

semaphore ensure

A

in the context of a race condition this can ensure that:

only one thread can be executing critical code on a shared resource at a time

this guarantees that a race condition cannot occur

89
Q

describe what

pre-emptive multitasking

is

A

this is a solution to multitasking

within this solution the operating system has control over when it will use the CPU.

it does this by setting a hardware timer that will interrupt any process

90
Q

describe a

state diagram and its components

A

this is a diagram that expresses the transition and states of a process.

  • ovals show the state of a process
  • arrows show the direction and transition of a process from one state to another

notes

  • All states and transitions should be labelled with there appropriate state or transition.
  • These are important for design as well as understanding
91
Q

describe what the

race condition

is

A

this is a phenomenon that occurs when two or more concurrent threads are sharing a resource

its a problem that lies where they both are carrying out tasks on that resource but neither has finished its task fully

the outcome is that depending on the order of who fnishes arrying out the task on that resource determines the final value of that resource

the final value of the resource will most likely be incorrect

92
Q

when two values are being used for a semaphore

what can the semaphore guarantee

A

in this case it can guarantee mutual exclusion that is that only one process can be executing a critical region of code at the same time.

this in turn can mitigate a race problem