Topic 11 – Context switching Flashcards
(92 cards)
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.
in regards to the context block what is the:
process state
in 7 steps describe how
buffer control is possible by using a semaphore
the steps that describe this are:
- a buffer is empty and has a size of 10 (the semaphore value is 10)
- a process wishes to deposit an item so makes a SEM_WAIT system call
- since the semaphore is not 0 the process can deposit the item in the buffer
- the semaphore value is now decremented to 9
- steps 2 - 5 will reapeat untill the semaphore reaches 0
- a process wishes to deposit an item so makes a SEM_WAIT system call
- 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)
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
what is the main feature of the processor that the operating system takes advantage of to achieve
pre-emptive multitasking
describe in 5 steps the
stack pointer
during an interrupt without a context switch
this without a context switch
- an interrupt occurs
- process A instruction pointer is placed on top the stack pointer
- the routine is placed inside the instruction pointer and is executed
- when the routine is finished it will call the RETURN instruction
- process A instruction pointer is pulled of the stack pointer and execution commences where it was paused
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
in regards to the context block what is the:
process priority
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
these actions include:
- Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
- 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
two use cases of this are:
- 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
- buffer control - this can also be used as a counter for example how many units are available in a buffer
name 2 uses of the
semaphore
name 6 pieces of information that would be found in the
context block
for a process
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
while the processor is in kernel mode what 2 items does the operating system have access to
while the processor is in this mode the opearting system can access:
- all instructions including privileged instructions
- all data structures including the context block
in summary these problems occure when:
- There is a shared resource
- There are critical regions of code acting on those shared resources
in two summary points when do Concurrency problems such as the race condition occur
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
describe the semaphore system call
SEM_WAIT
with this type of state the operating system knows that the process is currently using the CPU
if a
process is in a running state
what does the operating system know about the process
these actions include:
- Transition because of a system call: for example when an application program makes an I/O request or goes to sleep
- 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
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
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
name 6 pieces of information that would be found in the
context block
for a process
if a process is in this state then the operating system knows that it is waiting on an I/O operation to complete
if a
process is in a blocked state
what does the operating system know about the process
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
when can context switching occur
describe the semaphore system call
SEM_SIGNAL
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.
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
what is a
critical region
of code
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

describe what
pre-emptive multitasking
is
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
what is a
mutex
in regards to the context block what is the:
process priority
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
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”
what is
context switching
if a
process is in a ready state
what does the operating system know about the process
if a process is in this state then the operating system knows that it is waiting to be rescheduled to use the CPU
execpt for the semaphore system calls SEM_WAIT and SEM_SIGNAL
what other system calls are there that are associatied with the semaphore
There are also system calls that allow the creation and destroying of different semaphores so that different semaphores can be used by different applications






