Week 1 - processes , sheduling and threads Flashcards
(13 cards)
multitasking
Cpu switches between processes frequently and rapidly creating the illustion of processes being executed at same time
whether that actually happens depends on no of cores
creating process / loading program into memory
loading program into memory or creating a process:
we copy the static file ( binary) with text segments , data segments … into the process’ virtual adress space. We also allocate memory for the heap and the stack which grow towards each other. Heap grows in size when objects created when program runs and stack grows in size when local variables declared and function calls occur
process
instance of a program executed by the cpu
read
usually processes are allocated different memory but if processes are instances of the same program in theory you could share the data and text ( the binary file) but the stack and heap cannot be shared as they depend on what objects created and what functions called at runtime which can be different
what is context switching
when cpu switches between process:
process state is saved ( relevant info stored in the pcb) and we switch to another process whose state we have have to reload ( using values in pcb). time spent context switching is time the cpu is doing non productive work - not executing a process and so we seek to minimise as much as possible
what is premptive scheduling
Os interrupts a running process to allow another process to run
what is non premptive scheduling
we only switch processes when a process terminates or enters a waiting state
what is waiting time
time a process spends in the ready queue
Average waiting time is the average of all the waiting times of processes
WE WANT TO MINIMISE AWT (average wai..)
First come first serve scheduling
NON PREEMPTIVE
selects the process thats been in the queue the longest
the average waiting time impacted by the order of arrival of processes
SJF- Shortest job first
so essentially SJF (shortest job first algorithm)
gives priority to processes according to those that have the shortest burst time (time to execute)
minimises AWT compared to FCFS as FCFS only achieves this mimimum if processes come in that eact order
non - premptive : once a process is selected according to shortest burst time runs on cpu untll it terminates or enters waiting state
premptive - if a process is running but a process with a shorter burster ( shorter than remaining burst time of process arives) then we interrupt running process and switch to the process with shorter burst
issue with SJF is that it can lead to starvation as you can constantly have processes with shorter burst times arriving and so longer processes will be starved
priority scheduling
prioriorty :
priority not determined by burst time only but other factors ie age
can be non preemptive - even if process arrives with higher priority must wait for current process to terminate or enter a waiting state
can be premptive - if process arrives with higher priority it will interrupt the current process and we switch to higher priority one
different priority assignment to processes change the average waiting time
round robin scheduling
round robin scheduling:
uses a fifo CIRCULAR queue
we use time quantums - a maximum period of time a process executes on cpu before interrupt and forced to switch
if process finishes executing before time quantum finishes or enters a waiting state it releases cpu and next process scheduled
if maximum time quantum finishes and process isnt done then we prempt and place the process at the back of the queue unless theres no other process
waiting time is the time spent not executing
multi level queue scheduling
so multi level priority queues:
we have different levels of queues that can each have a different scheduling algorithm and we place different classes of processes in different queues
processes cant move between queues and top level is highest priority and bottom level is lowest priority