Process MGT
Process MGT
Chapter deals with; Processes, Process Transition/State, Process Control Blocks (PCBs), Process
Scheduling, Job Scheduling Versus Process Scheduling and Interrupts.
As a process executes, it changes state. The state may be any of the following:
There are two process models; one a two-state process model and the other a five-state process
model. In the two state the process is either running state or not- running state.
In the five –state process model, the state can be: New, Running, Ready, Waiting or Terminated.
1 | Page
As illustrated below:
For every process, the OS maintains a Process Control Block (PCB), a data structure that
represents the process and its state:
This contains information associated with each process. This may include:
Process state (running, not-running, etc.)
Process ID number
Program counter: A program counter is a register in a computer processor that contains
the address (location) of the instruction being executed at the current time. As each
instruction gets fetched, the program counter increases its stored value by 1.
CPU registers
CPU scheduling information (e.g., the waiting queue)
Memory-management information such as static or dynamic
2 | Page
Accounting information
I/O status information
3.5.1 Long-term scheduler (or job scheduler) – selects which processes should be brought
into the ready queue. It loads it into memory.
Long-term scheduler is invoked very infrequently. This can happen in a matter of seconds or
minutes and is slow.
3.5.2 Short-term scheduling (or CPU scheduler) – selects which process should be executed
next and allocates CPU. Short-term scheduler is invoked very frequently (milliseconds). It has to
be very fast.
When CPU switches to another process, the system must save the state of the old process and
load the saved state for the new process via a context switch. Context of a process is represented
in the PCB.
3 | Page
(a) Clock interrupt: Process has executed for the maximum allowable time slice
(b) I/O interrupts
(c) Memory fault: Memory address is in virtual memory so it must be brought into main
memory.
(d) Trap: Error occurred necessitating a switch or in the event of a process moving to Exit
state.
(e) Supervisor call such as such as file open
(a) Save context of processor including program counter and other registers
(b) Update the process control block of the process that is currently running
(c) Move process control block to appropriate queue - ready, blocked
(d) Select another process for execution
(e) Update the process control block of the process selected
(f) Update memory-management data structures
(g) Restore context of the selected process
3.6 Process Creation / Termination
3.8.2 Throughput:
4 | Page
This refers to the number of processes completed in a unit of time.
P1 24
P2 3
P3 3
P1 P2 P3
0 24 27 30
P2 , P3 , P1 .
5 | Page
The Gantt chart for the schedule is:
P2 P3 P1
0 3 6 30
When the CPU is available it is assigned to the process that has the smallest next CPU burst. If
two processes have the same length next CPU bursts, FCFS scheduling is used to break the tie. It
reduces on the average waiting time. Consider the following processes:
P1 6 1 0
P2 8 2 0
P3 7 3 0
P4 3 4 0
6 | Page
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority).
SJF is a priority scheduling where priority is the predicted to next CPU burst time.
It is designed especially for time sharing systems. A small unit of CPU time called a quantum,
usually 10-100 milliseconds is allocated to a process. After this time has elapsed, the process is
preempted and added to the end of the ready queue.
The Ready queue is kept as FCFS processes. No job is allocated the CPU for more than one
quantum in a row. If its CPU burst exceeds the time quantum,, it is preempted and put in the
ready queue.
P1 24
P2 3
P3 3
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Ready queue is partitioned into separate queues; Foreground (interactive) and background
(batch).
Each queue has its own scheduling algorithm, foreground – RR, background – FCFS. Scheduling
7 | Page
must be done between the queues.
Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of
starvation. Time slice – each queue gets a certain amount of CPU time which it can schedule
amongst its processes; i.e., 80% to foreground in RR, 20% to background in FCFS.
A process can move between the various queues; aging can be implemented this way.
8 | Page