week 5 - L1 - Process management Flashcards
process
- what is a process
- what does it consist of
Process
- A process is a running program ( also unit of execution)
- It is the instantiation of a program.
- It consists of code and the data, in memory to run
serial processing
- does it have an OS?
- what do the machines need to run?
- what’s the setup for it?
Serial processing
- No operating system
- Machines run from a console with display lights, input device, and printer
o Display lights – error messages
o Input device – punch card, tape
o Printer – output - Setup included loading and compiling the program, and loading and linking common functions – very time consuming (errors!)
Uniprogramming
- what must the processor do?
- how does it work?
- Processor must wait for the I/O instruction to complete before proceeding
- We can see that the way the program works is it runs then waits for instructions, then runs and wait for instructions… and so on
RUN _ WAIT RUN _ WAIT
Simple batch Systems
- what does the user do?
- how does the user prepare jobs?
- what happens to jobs with similar requirements
- what are the steps?
The user doesn’t interact with the system directly.
The user prepares jobs using an offline device to punch cards.
Jobs with similar requirements are batched together as a group.
- Resident monitor program: scheduling, privileged operations
- Users submit jobs to operate
- Operator batches jobs
- Monitor controls a sequence of events to process batch
- When one job is finished the control returns to Monitor which reads next job
- Monitor handles scheduling (FIFO aka first in first out)
multiprogramming
- what does the processor do?
- what does the sequence in which programs are executed depend on?
- what can happen after an interrupt handler completes? and what does it depend on
Multiprogramming
- As the name indicated, the processor has more than one process to execute
- The sequence in which programs are executed depends on
o Their relative priority
o Whether they are waiting for I/O(input/output) - After an interrupt handler completes, the control MAY NOT RETURN to the program that was executing at the time of the interrupt
o (depending on the scheduling)
Time sharing systems
- what does it use to handle multiple jobs?
- what happens with the processor time?
- how do multiple users access the system? through what?
- Time sharing system uses multiprogramming to handle multiple interactive jobs
- The processor’s time is shared between multiple users
- Also multiple users simultaneously access the system through terminals
process
- what does it contain?
A process contains:
- Address space
o Code and data for running the program
- CPU state o Program counter(PC) pointing to the next instruction o Stack pointer (SP) o PC and ST o General purpose register values
- Set of resources o files o network connections o other hardware resources - A program is a piece of code, while a process is a dynamic instance of a program
Process address space
- what is it made of?
- what do each of them contain?
STACK – stores temporary data such as method parameters, method return addresses and local variables
HEAP – is dynamically allocated memory to a process while it is running
- The memory is deallocated when the process stops running
STATIC DATA – section stores static variables
- i.e. a variable that has been allocated statically
PROGRAM COUNTER (PC) – is a CPU register that points to the next instructions to be fetched and executed
Process control block (PCB)
- what is it?
- what does it use to uniquely identify processes?
- what does it keep when the process is not running?
- is it the same in different systems?
- how many fields can it have in Linux?
- what are they?
- in order to keep track of a process state the CPU maintains data structure called process control block PCB which stores information about it
- processes are identified by an unique integer process ID called PID
- the PCB is used to keep all the process execution state when it’s not running (so basically PC, SP, register values etc)
o i.e. PC, SP, register values etc - the PCB is the representation of a process used by OS
o it can very in different operating systems
- PCB is a data structure with many fields (in Linux there are over 95 defined in task struct)
- The main fields are:
o Process ID (PID)
o Parent process ID (PPID) – pointer to parent process
o Process state (ready, running, waiting etc)
o Pointers for state queues
o PC, SP, register current values
o Address space information
o Process privileges (i.e. allow access to system resources)
o CPU scheduling information (priority)
o Memory management information
o Accounting information(CPU time for process execution, time limits etc.)
o IO status information (list of I/O devices allocated to the process)
o User ID(Linux)
Context Switching
- what values does the CPU currently contain?
- what is it?
- how does it work?
- what is scheduling?
- who controls context switching?
- When a process is running, the CPU contains the current values for: o PC (program counter) o SP (stack pointer) o And other registers
- Control switching is the act of switching the CPU from one process to another
- To do this it saves the CPU state of running process in its PCB
- When the OS returns the process to the running state, it loads the CPU registers with values stored in the process PCB
- SCHEDULING is the task of choosing which process to run next
o So the context switching is controlled by the scheduler - The concept of multi-processing revolves around context switching which allows more than one task (process) to run at the same time
process control
- what are the steps of creating a process?
Process control
a unique identifier is assigned to the new process
memory is allocated to it
the PCB is constructed and initialised
the PCB is placed in te queue
other OS modules are notified about the process
The process of creating a process step by step:
- A unique identifier is assigned to the new process
a. One new entry is added to the primary process table - Memory is allocated for the process
a. Includes program, data, stack and PCB - The PCB is constructed and initialised
a. ID, state = “ready”, CPU state = empty, resources = none - The PCB is placed in the queue (which is a linked list)
- Other O/S modules are notified about the new process
a. And create or expand other data structures to accommodate info about the new process
Event that trigger O/S switch processes
- what are the 2 main events?
- examples of some?
- how do they differ?
interrupts and traps
- Interrupts – external, asynchronous events, independent of the currently executed process instructions
o Clock interrupts
O/S checks time and may block process
o I/O interrupts
Data has come, O/S may unblock process
o Memory fault
O/S may block process that must wait for a missing page in memory to be swapped in
- Traps
o exceptions – internal, involuntary synchronous events caused by instructions
O/S may terminate or recover a process
o System calls – internal, voluntary synchronous events calling a specific O/S service
After service completed, O/S may either resume or block the calling process depending on I/O, priorities, etc
Process life cycle
- what are the steps of a process?
- how are disk drives compared to CPU speeds?
- Processes are created(born), carry out tasks, go to sleep, die (or get killed)
- They may differ from OS to OS but in general they are in on of the following states:
- Start – initial state when process is created
- Ready – process is waiting to be assigned a CPU
- Running – the process is assigned a CPU by the OS scheduler and instructions are being executed
- Waiting – the process is waiting for the physical things to happen such as a bloc of dish drive data to become ready
- Terminated or exit (the process has finished its task and is placed in the terminated state by the OS where it waits to be removed from memory)
o Disk drives are slow compared to CPU speeds
process scheduling types
- what are the 3 types?
- how are they different?
Process scheduling types
- Long term scheduling (job scheduler)
o Define which processes are admitted to the system - Medium term scheduling
o Part of the swapping function - Short term scheduling
o Which process has control of the CPU
short term scheduling - what is the aim of it? - what happens sometimes when we want to optimise aspects of system behavior? - what is the trade of switching? -
Short term scheduling
- Aim is to allocate processor time in order to optimize one or more aspects of system behaviour
- Sometimes this includes pre-emptively switching processes
o OS takes CPU control from one process and allocates it to another
o Basically moves control of CPU from one process to another - Every time processes switch, there is an overhead, while the dispatcher runs
o Basically a trade-off, because there is overhead. Some things need to be saved so time/resources are wasted on that and other things