what is multiprogramming?
a form of parallel processing where several programs run at the same time on a uniprocessor system.
because there is only one processor, there is no true simultaneous execution of different programs. Instead, the operating system executes part of one program, then part of another, etc. (pseudo-parallelism.)
To the user, it appears that multiple programs are executing at the same time
what are other names for a process?
in a batch system - job
in a time shared system - user program/ task
unit of work
what is a process?
a program being executed on an OS. the program is converted into an executable file, file is run and loaded to memory.
what is the difference between a process and a program?
process is an active entity as program counter specifies the next instruction to execute and has a set of resources. program is passive entity
how do processes use resources?
processes need resources (CPU time, memory, files, i/o devices) to accomplish task. resources allocated to process when created or when executed (by operating system)
how is a program/ executable file loaded into memory?
GUI = double click
command line = enter fine name in command line
whatâs an example of a process that is an execution environment?
java virtual machine which executes as a program
what is a system?
collection of processes e.g. os processes execute system code/ user processes execute user code. different processes can execute concurrently.
how many threads can a process have?
traditionally processes only contained 1 thread
modern os can support processes with multiple threads
how many processes can a program spawn?
one program can spawn multiple processes e.g. users running different copies of the same program
2 processes from same program have separate execution sequences e.g. same text section but different data, heap, stack sections
one process can spawn other processes
what is the os responsible for during process and thread management?
create + delete user and system processes
schedule processes
synchronisation, communication, deadlock handling â if processes not scheduled properly, deadlock occurs
gives us tools to see which process are running as processes can run in the background
what is a process made of?
4 process components
text section
stack
data section
heap
0âŠMax denotes the total memory allocated for the process.
what is the text section in a process?
program code and current activity status. current activity status is specified by the program counter value and contents of process registers.
what is the stack in a process?
temporary data saved as a function with parameters, return addresses and local variable
what is the data section in a process?
global variables
what is the heap in a process?
memory dynamically added to the process during runtime
what is a process state?
representation of the processâs current activity.
as process runs it changes state based on the current activity of the process.
there are different states depends on the needs of the process
what are the possible process states?
5 states
new
running
ready
waiting
terminated
what is the new process state?
The process is being created (not executing)
what is the running process state?
Instructions are being executed.
what is the ready process state?
The process is waiting to be assigned to a processor.
what is the waiting process state?
The process is waiting for some event to occur (e.g. waiting for I/O device completion or reception of a signal).
what is the terminated process state?
The process has finished execution.
how many processes can be in each state at any given time
only one process can be running at a time
many processes can be ready or waiting at a time
how are processes represented by the OS?
PCB, Process Control Block
what is the process control block?
where info is stored about a process
needed so the OS has the info it needs to schedule and allocate
PCB will vary from process to process
how does the PCB work?
PCB updated every time a process changes state (e.g. normal state change, whenever the process stops running) so OS knows what the process is doing
what are the components of the process control block?
process state
program counter
CPU registers
CPU scheduling information
memory management information
accounting information
I/O status information
got 7 total components
what is the process state in the PCB?
can be new, ready, waiting etc.
what is the program counter of the PCB?
indicates the address of the next instruction to be executed for this process. state needs to be saved if interrupt occurs so process can continue correctly afterwards
what is the CPU registers in the PCB?
data stores
the registers vary in number and type, depending on the computer architecture. include
accumulators
index registers
stack pointers
general-purpose registers
condition-code information
state needs to be saved if an interrupt occurs so the process can continue correctly afterwards
what is the CPU scheduling information in the PCB?
information used for scheduling the CPU
e.g. process priority, pointers to scheduling queues (ready queue) and other scheduling parameters
what is the memory management information in the PCB?
information to manage memory
e.g. value of the base registers, limit registers, page tables or segment tables, depending on the OS used
what is the accounting information in the PCB?
information including
e.g. amount of CPU and time used, time limits, account numbers, process numbers
what is the I/O status information in the PCB?
information including
e.g. list of I/O devices allocated to a process, list of open files
what is the state diagram for process states and PCB?
shows how state can change during process lifecycle
since the state regularly changes that means the process state component in the PCB is also regularly updated to match
[ memorise the diagram including the words on the arrows
new â ready = admitted
ready â running = scheduler
running â waiting = I/O or event wait
waiting â ready = I/O or event completion
running â ready = interrupt
running â terminated = exit
how does the CPU switch from one process to another during an interrupt?
CPU switches from process to process very quickly without the userâs realising that they arenât running in parallel
Process0 executes
interrupt occurs
saves state of process0 to PCB0
reloads the state of process1 from PCB1
after state is loaded and cpu + memory allocated process1 executes
same process to return control
how are processes scheduled in the operating system?
using schedulers and scheduling queues
why do we need to schedule processes?
to maximise CPU during multiprogramming so some processes can run at all times.
to allow time-sharing to occur = switching the CPU between processes frequently so that users can interact with each running program.
multiprogramming only has a single cpu = never more than 1 process running at a time and other processes have to wait until the CPU is free and can be rescheduled
what does the process scheduler do?
process scheduler selects an available process (from a set of available processes) for the CPU to execute. there are many scheduling queues that a process can be put into based on how the scheduler allocates CPU time.
what are scheduling queues?
lists of processes that allows the OS to keep track of the needs of different processes
process scheduler picks relevant process from relevant queue and carry out relevant operation
each queue has a queue header
can have priority queues based on the different schedulers, not always FIFO
what are the different types of scheduling queues?
job queue
ready queue
I/O aka. device queue
what is the job queue?
consists of all processes in the system, processes are added to job queue the moment they ENTER the system
what is the ready queue?
processes that are in the ready state and reside in main memory.
ready queue header contains pointers to the first and last PCB in the list.
each PCB has a pointer that points to the next PCB in the ready queue
what is the I/O queue?
list of processes that are waiting for an I/O device (as a process might need to use an I/O device that is already being used by another process). each device has itâs own device queue
how is process scheduling represented?
queueing diagram
each box is a queue
each circle is a resource that serve the queues
arrows show the flow of processes in the system
blue text shows the process state
how does the process state, PCBs and OS queues work together to schedule processes?
relates to the process state diagram
new process is put into ready queue and waits until selected for execution or dispatched.
when CPU has been allocated to the process, process leaves ready queue and is in running state
in running state the process can
process issues I/O request and be put into device queue, waiting state
process creates new child process and waits for child to terminate, waiting state
process is forcibly removed from CPU due to interrupt, waits for inturrpt to finish and moves straight into ready queue, ready state
after waiting state, process returns back to ready queue, ready state
cycle between [ready, running, waiting]
process can repeat cycle until it terminates. when it terminates it is removed from all queues and PCB and resources are deallocated meaning PCB no longer exists, terminated state
how are processes stored on a batch system?
Often, in a batch system, more processes are submitted than can be executed immediately These processes are spooled to a mass-storage device (typically a disk), where they are kept for later execution
what are the different types of schedulers?
OS has 2 types of schedulers:
short term scheduler/ CPU scheduler
long term scheduler/ job scheduler
what is the short term scheduler?
Selects which process should be executed next and allocates CPU (running)
Sometimes the only scheduler in a system
invoked frequently (milliseconds)
must be fast as currently executing I/O bound processes may run a v short time before waiting for I/O, so a new process needs to be ready to execute to not waste CPU
what is the long term scheduler?
Selects which processes should be brought into the ready queue
invoked infrequently (seconds, minutes) and may be slow
The long-term scheduler controls the degree of multiprogramming (number of processes in memory). stable multiprogramming degree = average rate of processes crated = average rate of processes departing the system
to keep stable multiprogramming degree long term scheduler might only invoke when process leaves the system and can take longer to decide which process to select next
what factors makes it difficult for the OS scheduler to schedule processes?
ensure it is load balancing -
want to use resources as efficiently as possible
not all processes do the same amount of work or have the same needs (some need more CPU time than others, more calculations, more use of I/O)
what are the 2 main types of processes?
I/O bound processes
CPU bound processes
what are I/O bound processes?
spends more time doing I/O than computations, many short CPU bursts
what are CPU bound processes?
spends more time doing computations; few very long CPU bursts
what mix of processes should the long-term scheduler select and why?
Long-term scheduler should select a good process mix of I/O bound and CPU bound processes otherwise system will be unbalanced and lesser performance
if all are IO bound, ready queue will be empty and short term scheduler has nothing to do
if all are CPU bound, IO queue will be empty and devices unused
what is another type of scheduler used by time sharing systems?
medium term scheduler
what is the medium term scheduler?
does swapping, where a process currently in memory is swapped out and swapped back in, reducing the degree of multiprogramming
swapping may be needed to improve process mix and the current process might change itâs memory requirement and thereâs not enough available memory to complete the process