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

Week 03 Lecture Chapter 3

The document explains the concept of processes in operating systems, highlighting the difference between a process and a program, as well as the various states a process can be in during execution. It details the structure and function of the Process Control Block (PCB), process scheduling, and the role of schedulers and dispatchers in managing CPU resources. Additionally, it outlines the criteria for evaluating CPU scheduling algorithms, including CPU utilization, throughput, turnaround time, waiting time, and response time.
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)
9 views

Week 03 Lecture Chapter 3

The document explains the concept of processes in operating systems, highlighting the difference between a process and a program, as well as the various states a process can be in during execution. It details the structure and function of the Process Control Block (PCB), process scheduling, and the role of schedulers and dispatchers in managing CPU resources. Additionally, it outlines the criteria for evaluating CPU scheduling algorithms, including CPU utilization, throughput, turnaround time, waiting time, and response time.
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/ 22

Operating System

The Process
□ A process is a program in execution
□ A program itself is not a process.
□ The fundamental difference between process and program are:
1. A process is a program in execution, where a program is an
executable file residing on the disk (secondary storage) in a
directory.
2. A process is termed as an ‘active entity’ since it is always
stored in the main memory and disappears if the machine is
power cycled, where A program is termed as a ‘passive entity’
which exists in the secondary storage persistently even if the
machine reboots.
3. Executing multiple instances of the ‘Calculator’ program. Each
of the instances is termed as a process. where (Windows) The
‘Calculator’ program is stored at
“c:\windows\system32\calc.exe”.
Process State

□ As a process executes, it changes state.


□ The state of a process is defined in part by the current activity
of that process. A process may be in one of the following
states:
❑ New: The process is being created.
❑ Running: Instructions are being executed.
❑ Waiting: The process is waiting for some event to occur
(such as an I/O completion or reception of a signal).
❑ Ready: The process is waiting to be assigned to a
processor.
❑ Terminated: The process has finished execution.
Process State (Cont.)

Diagram of process state


Process Control Block
□ Each process is represented in the operating system by a
process control block (PCB); also called a task control
block.
□ A PCB contains many pieces of information associated with a
specific process, including these:
❑ Process state.
❑ Program counter.

❑ CPU registers.

❑ CPU-Scheduling information.
❑ Memory-management information.
❑ Accounting information.

❑ I/O status information.


Process Control Block (Cont.)

I. Process state. The state may be new, ready, running,


waiting, halted, and so on.
II. Program counter. The counter indicates the address of the
next instruction to be executed for this process.
III. CPU registers. The registers vary in number and type,
depending on the computer architecture. They include
accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information.
Along with the program counter, this state information must
be saved when an interrupt occurs, to allow the process to be
continued correctly afterward.
Process Control Block (Cont.)
IV. CPU-Scheduling information. This information includes a
process priority, pointers to scheduling queues, and any
other scheduling parameters.
V. Memory-management information. This information may
include such items as the value of the base and limit registers
and the page tables, or the segment tables, depending on the
memory system used by the operating system.
VI. Accounting information. This information includes the
amount of CPU and real time used, time limits, account
numbers, job or process numbers, and so on.
VII. I/O status information. This information includes the list of
I/O devices allocated to the process, a list of open files, and
so on.
Process Control Block (Cont.)

Diagram showing CPU switch from process to process.


Process Scheduling
▪ The objective of multiprogramming is to have some
process running at all times, to maximize CPU
utilization.
▪ The objective of time sharing is to switch the CPU
among processes so frequently that users can interact
with each program while it is running.
▪ To meet these objectives, the process scheduler selects
an available process (possibly from a set of several
available processes) for program execution on the CPU.
▪ For a single-processor system, there will never be more
than one running process. If there are more processes,
the rest will have to wait until the CPU is free and can be
rescheduled.
Process Scheduling Queue
▪ As processes enter the system, they are put into a job queue,
which consists of all processes in the system.
▪ The processes that are residing in main memory and are ready
and waiting to execute are kept on a list called the ready
queue.
▪ When a process is allocated the CPU, it executes for a while
and eventually quits, is interrupted, or waits for the
occurrence of a particular event, such as the completion of an
I/O request. Suppose the process makes an I/O request to a
shared device, such as a disk. Since there are many processes
in the system, the disk may be busy with the I/O request of
some other process. The process therefore may have to wait
for the disk. The list of processes waiting for a particular I/O
device is called a device queue. Each device has its own
device queue.
Queueing-Diagram

▪ A common representation of process scheduling is a queuing

diagram.

▪ A new process is initially put in the ready queue. It waits

there until it is selected for execution, or dispatched. Once the


process is allocated the CPU and is executing, one of several
events could occur:
Queuing-Diagram representation of process scheduling

I. The process could issue an I/O request and then be placed in an I/O
queue.
II. The process could create a new child process and wait for the child’s
termination.
III. The process could be removed forcibly from the CPU, as a result of an
interrupt, and be put back in the ready queue.
Schedulers
▪ Often, 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.
▪ The long-term scheduler, or job scheduler, selects processes from this
pool and loads them into memory for execution.
❑ The long-term scheduler executes much less frequently; minutes may
separate the creation of one new process and the next, it means it’s
invoked infrequently. Because of the longer interval between
executions, the long-term scheduler can afford to take more time to
decide which process should be selected for execution, it may work
slow (seconds, minutes).
▪ The short-term scheduler, or CPU scheduler, selects from among the
processes that are ready to execute and allocates the CPU to one of them.
❑ It is executed at least once every 100 milliseconds, it means it’s
invoked frequently. Because of the short time between execution, it
must be fast (milliseconds).
Context Switch

▪ Switching the CPU to another process requires performing a


state save of the current process and a state restore of a
different process. This task is known as a context switch.

▪ Context switching is a combination of two functions:


I. A state save of the current process of the CPU,. i.e. save
the state information of the current process in PCB.
II. A state restore to resume operations, i.e. resume the next
process from the ready queue.
Context Switch (Cont.)

▪ Switching speed varies from machine to machine, depending


on
❑ the memory speed,
❑ the number of registers that must be copied, and
❑ the existence of special instructions (such as a single
instruction to load or store all registers).
▪ A typical speed is a few milliseconds.
CPU Scheduling
▪ The objective of multiprogramming is to have some process running
at all times, to maximize CPU utilization.
▪ CPU scheduling is the basis of multiprogrammed operating systems.
By switching the CPU among processes, the operating system can
make the computer more productive.
▪ When one process has to wait, the operating system takes the CPU
away from that process and gives the CPU to another process. This
pattern continues. Every time one process has to wait, another
process can take over use of the CPU.
▪ Scheduling of this kind is a fundamental operating-system function.
▪ Whenever the CPU becomes idle, the operating system must select
one of the processes in the ready queue to be executed. The selection
process is carried out by the short-term scheduler, or CPU scheduler.
The scheduler selects a process from the processes in memory that
are ready to execute and allocates the CPU to that process.
Preemptive Scheduling

CPU-scheduling decisions may take place under the following


four circumstances:

1. When a process switches from the running state to the


waiting state.
2. When a process switches from the running state to the
ready state.
3. When a process switches from the waiting state to the
ready state.
4. When a process terminates.
Dispatcher
□ Another component involved in the CPU-scheduling function is
the dispatcher.
□ The dispatcher is the module that gives control of the CPU to the
process selected by the short-term scheduler.
□ This function involves the following:
❑ Switching context.
❑ Switching to user mode.
❑ Jumping to the proper location in the user program to restart
that program.
□ The dispatcher should be as fast as possible, since it is invoked
during every process switch.
□ The time it takes for the dispatcher to stop one process and start
another running is known as the dispatch latency.
Scheduling Criteria

□ Different CPU-scheduling algorithms have different properties,


and the choice of a particular algorithm may favor one class of
processes over another. Many criteria have been suggested for
comparing CPU-scheduling algorithms.
□ The criteria include the following:

1. CPU utilization. keeping the CPU as busy as possible.


Conceptually, CPU utilization can range from 0 to 100 percent.
2. Throughput: Number of processes that complete their
execution per time unit. For long processes, this rate may be
one process per hour; for short transactions, it may be ten
processes per second.
Scheduling Criteria (Cont.)

1. Arrival time: The time at which process enter the Ready


Queue or state.

2. Brust Time: Time required by a process to get execute on


CPU.

3. Completion Time: The time at which process complete it’s


execution.
Scheduling Criteria (Cont.)
Turnaround time. The interval from the time of submission of
a process to the time of completion. i.e. amount of time to
execute a particular process. Turnaround time is the sum of the
periods spent waiting to get into memory, waiting in the ready
queue, executing on the CPU, and doing I/O.
WT = Completion time – Arrival Time

Waiting time. The CPU-scheduling algorithm does not affect


the amount of time during which a process executes or does
I/O. It affects only the amount of time that a process spends
waiting in the ready queue. Waiting time is the sum of the
periods spent waiting in the ready queue.
WT = Turn Around Time – Brust Time
Scheduling Criteria (Cont.)

Response time. Amount of time it takes from when a request


was submitted until the first response is produced. It is the time it
takes to start responding, not the time it takes to output the
response.

It is desirable to:
▪ Maximize CPU utilization.
▪ Maximize throughput.
▪ Minimize turnaround time.
▪ Minimize waiting time.
▪ Minimize response time.

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