0% found this document useful (0 votes)
21 views

Process MGT

Notes about processes that are majorly in computer science degree

Uploaded by

cjshak69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Process MGT

Notes about processes that are majorly in computer science degree

Uploaded by

cjshak69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Processes

Chapter deals with; Processes, Process Transition/State, Process Control Blocks (PCBs), Process
Scheduling, Job Scheduling Versus Process Scheduling and Interrupts.

3.1 Process Concept:

A Process refers to a program in execution; process execution must progress in sequential


fashion. A process includes: program counter, data section having program instructions, stack
and heap. Stack is used for static memory allocation and Heap for dynamic memory allocation,
both stored in the computer's RAM. Variables allocated on the stack are stored directly to the
memory and access to this memory is very fast, and its allocation is dealt with when the program
is compiled. This information is used in keeping track of the process.

3.2 Process State:

As a process executes, it changes state. The state may be any of the following:

(a) New: The process is being created


(b) Running: Instructions are being executed
(c) Waiting: The process is waiting for some event to occur
(d) Ready: The process is waiting to be assigned to a processor
(e) Terminated: The process has finished execution:

3.2.1 Process State Models:

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:

3.2.2 State Transitions in Five-State Process Model:

(a) New Ready:


Admitted to ready queue; can now be considered by CPU scheduler
(b) Ready Running:
CPU scheduler chooses that process to execute next, according to some scheduling
algorithm.
(c) Running Ready:
Process has used up its current time slice
(d) Running Blocked:
Process is waiting for some event to occur (for I/O operation to complete, etc.)
(e) Blocked Ready:
Whatever event the process was waiting on has occurred

3.3 Process Control Block (PCB)

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.4 Process Scheduling Queues

Job queue – set of all processes in the system


Ready queue – set of all processes residing in main memory, ready and waiting to execute.
Device queues – set of processes waiting for an I/O device. Processes migrate among the various
queues

3.5 Process Scheduling:

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.

The long-term scheduler controls the degree of multiprogramming.


Processes can be described as either:
(a) I/O-bound process: Spends more time doing I/O than computations, many short CPU
bursts.
(b) CPU-bound process – spends more time doing computations; few very long CPU bursts

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.

3.6 Process Switch

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.6.1 When to Switch Process:

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

3.6.2 Change of Process State:

(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

Creation of processes may involve assigning a unique process identifier to a process,


allocation of space for the process. It may also require initializing the process control
block. Termination can occur when the user logs off or when there are errors and faults.

3.7.1 Reasons for process creation

(a) User logs on.


(b) User starts a program
(c) OS creates process to provide a service (e.g. printer daemon to manage printer)
(d) Program starts another process (e.g. Netscape calls XP to display a picture)

3.7.2 Reasons for process termination:

(a) Normal completion.


(b) Arithmetic error, or data misuse (e.g. wrong type)
(c) Invalid instruction execution
(d) Insufficient memory available, or memory bounds violation
(e) Resource protection error
(f) I/O failure

3.8 Criteria for Comparing Scheduling Algorithms:

3.8.1 CPU Utilization:


This refers to the percentage of time that the CPU is busy.

3.8.2 Throughput:
4 | Page
This refers to the number of processes completed in a unit of time.

3.8.3 Turnaround time:


The length of time it takes to run a process from initialization to termination, including all
the waiting time.

3.8.4 Waiting time:


This refers to the total amount of time that a process is in the ready queue.

3.8.5 Response time:


The time between when a process is ready to run and its next I/O request.

3.9 Scheduling Algorithms:

3.9.1 First-Come, First-Serve (FCFS) Scheduling:

This is the simplest scheduling Algorithm. It uses the principle of FIFO.

Process Burst Time

P1 24

P2 3

P3 3

Suppose that the processes arrive in the order: P1 , P2 , P3

The Gantt Chart for the schedule is:

P1 P2 P3

0 24 27 30

Waiting time for P1 = 0; P2 = 24; P3 = 27

Average waiting time: (0 + 24 + 27)/3 = 17

Suppose that the processes arrive in the order

P2 , P3 , P1 .

5 | Page
The Gantt chart for the schedule is:

P2 P3 P1

0 3 6 30

Waiting time for P1 = 6; P2 = 0; P3 = 3

Average waiting time: (6 + 0 + 3)/3 = 3

Much better than previous case.

3.9.2 Shortest-Job-First (SJR) Scheduling

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:

Process Duration/B.T Order Arrival Time

P1 6 1 0

P2 8 2 0

P3 7 3 0

P4 3 4 0

P4 waiting time: 0-0

P1 waiting time: 3-0

P3 waiting time: 9-0

P2 waiting time: 16-0

The total running time is: 24

The average waiting time (AWT):

(0+3+9+16)/4 = 7 time units

3.9.3 Priority Scheduling

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.

Problem ≡ Starvation – low priority processes may never execute.

Solution ≡ Aging – as time progresses increase the priority of the process.

3.9.4 Round Robin (RR)

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.

Example of RR with Time Quantum = 4

Process Burst Time

P1 24

P2 3

P3 3

The Gantt chart is:

P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

Average waiting time = [(30-24) +4+7]/3 = 17/3 =5.66

3.9.5 Multilevel Queue

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.

3.9.6 Multilevel Feedback Queue

A process can move between the various queues; aging can be implemented this way.

Multilevel-feedback-queue scheduler defined by the following parameters; Number of queues,


scheduling algorithms for each queue, method used to determine when to upgrade a process.
Method used to determine when to demote a process and method used to determine which queue
a process will enter when that process needs service

8 | Page

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy