0% found this document useful (0 votes)
15 views16 pages

Process Scheduling

A Process Control Block (PCB) is a data structure used by the Operating System to manage process information, enabling the interruption and resumption of processes. Processor scheduling is critical for optimizing system performance and is divided into long-term, medium-term, and short-term scheduling functions, each serving different roles in managing process execution. Various scheduling algorithms, such as First-Come, First-Served and Round Robin, are employed to allocate CPU time effectively, balancing user-oriented and system-oriented criteria.

Uploaded by

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

Process Scheduling

A Process Control Block (PCB) is a data structure used by the Operating System to manage process information, enabling the interruption and resumption of processes. Processor scheduling is critical for optimizing system performance and is divided into long-term, medium-term, and short-term scheduling functions, each serving different roles in managing process execution. Various scheduling algorithms, such as First-Come, First-Served and Round Robin, are employed to allocate CPU time effectively, balancing user-oriented and system-oriented criteria.

Uploaded by

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

Process Control Block (PCB):

A Process Control Block is a data structure maintained by the Operating System for every
process. The PCB is identified by an integer process ID (PID).

The information in the preceding list is stored in a data structure, typically called a process
control block (the figure above), that is created and managed by the OS. The significant point
about the process control block is that it contains sufficient information so that it is possible to
interrupt a running process and later resume execution as if the interruption had not occurred.

The process control block is the key tool that enables the OS to support multiple processes and to
provide for multiprocessing. When a process is interrupted, the current values of the program
counter and the processor registers (context data) are saved in the appropriate fields of the
corresponding process control block, and the state of the process is changed to some other value,
such as blocked or ready (described subsequently). The OS is now free to put some other process
in the running state. The program counter and context data for this process are loaded into the
processor registers and this process now begins to execute.
Thus, we can say that a process consists of program code and associated data plus a process
control block. For a single-processor computer, at any given time, at most one process is
executing and that process is in the running state.

The aim of processor scheduling is to assign processes to be executed by the processor or


processors over time, in a way that meets system objectives, such as response time, throughput,
and processor efficiency. In many systems, this scheduling activity is broken down into three
separate functions: long-, medium-, and short-term scheduling.
The names suggest the relative time scales with which these functions are performed.
Long-term scheduling is performed when a new process is created. This is a decision whether to
add a new process to the set of processes that are currently active. Medium-term scheduling is a
part of the swapping function. This is a decision whether to add a process to those that are at
least partially in main memory and therefore available for execution. Short-term scheduling is
the actual decision of which ready process to execute next. Scheduling affects the performance
of the system because it determines which processes will wait and which will progress. This
point of view is presented in Figure (Levels of Scheduling) below, which shows the queues
involved in the state transitions of a process. Fundamentally, scheduling is a matter of managing
queues to minimize queueing delay and to optimize performance in a queueing environment. or
user program becomes a process and is added to the queue for the short-term scheduler. In some
systems, a newly created process begins in a swapped-out condition, in which case it is added to
a queue for the medium-term scheduler.
In a batch system, or for the batch portion of an OS, newly submitted jobs are routed to disk and
held in a batch queue. The long-term scheduler creates processes from the queue when it can.
There are two decisions involved. The scheduler must decide when the OS can take on one or
more additional processes. And the scheduler must decide which job or jobs to accept and turn
into processes. We briefly consider these two decisions.
The decision as to when to create a new process is generally driven by the desired degree of
multiprogramming. The more processes that are created, the smaller is the percentage of time
that each process can be executed (i.e., more processes are competing for the same amount of
processor time). Thus, the long-term scheduler may limit the degree of multiprogramming to
provide satisfactory service

Long-Term Scheduling
The long-term scheduler determines which programs are admitted to the system for processing.
Thus, it controls the degree of multiprogramming. Once admitted, a job
Levels of Scheduling

or user program becomes a process and is added to the queue for the short-term scheduler. In
some systems, a newly created process begins in a swapped-out condition, in which case it is
added to a queue for the medium-term scheduler.
In a batch system, or for the batch portion of an OS, newly submitted jobs are routed to disk and
held in a batch queue. The long-term scheduler creates processes from the queue when it can.
There are two decisions involved. The scheduler must decide when the OS can take on one or
more additional processes. And the scheduler must decide which job or jobs to accept and turn
into processes. We briefly consider these two decisions.
The decision as to when to create a new process is generally driven by the desired degree of
multiprogramming. The more processes that are created, the smaller is the percentage of time
that each process can be executed (i.e., more processes are competing for the same amount of
processor time). Thus, the long-term scheduler may limit the degree of multiprogramming to
provide satisfactory service
Queueing Diagram for Scheduling
to the current set of processes. Each time a job terminates, the scheduler may decide to add one
or more new jobs. Additionally, if the fraction of time that the processor is idle exceeds a certain
threshold, the long-term scheduler may be invoked.
The decision as to which job to admit next can be on a simple first-come-first- served (FCFS)
basis, or it can be a tool to manage system performance. The criteria used may include priority,
expected execution time, and I/O requirements.
For example, if the information is available, the scheduler may attempt to keep a mix of
processor-bound and I/O-bound processes. 2 Also, the decision can depend on which I/O
resources are to be requested, in an attempt to balance I/O usage.
For interactive programs in a time-sharing system, a process creation request can be generated by
the act of a user attempting to connect to the system. Time-sharing users are not simply queued
up and kept waiting until the system can accept them.
Rather, the OS will accept all authorized comers until the system is saturated, using some
predefined measure of saturation. At that point, a connection request is met with a message
indicating that the system is full and the user should try again later.

Medium-Term Scheduling
Medium-term scheduling is part of the swapping function. Typically, the swapping-in decision is
based on the need to manage the degree of multiprogramming. On a system that does not use
virtual memory, memory management is also an issue. Thus, the swapping-in decision will
consider the memory requirements of the swapped-out processes.

Short-Term Scheduling
In terms of frequency of execution, the long-term scheduler executes relatively infrequently and
makes the coarse-grained decision of whether or not to take on a new process and which one to
take. The medium-term scheduler is executed somewhat more frequently to make a swapping
decision. The short-term scheduler, also known as the dispatcher, executes most frequently and
makes the fine-grained decision of which process to execute next.
The short-term scheduler is invoked whenever an event occurs that may lead to the blocking of
the current process or that may provide an opportunity to preempt a currently running process in
favor of another. Examples of such events include:
• Clock interrupts
• I/O interrupts
• Operating system calls
• Signals (e.g., semaphores)

SCHEDULING ALGORITHMS.2 SCHEDULING ALGORITHMS

Short-Term Scheduling Criteria


The main objective of short-term scheduling is to allocate processor time in such a way as to
optimize one or more aspects of system behavior. Generally, a set of criteria is established
against which various scheduling policies may be evaluated.
The commonly used criteria can be categorized along two dimensions. First, we can make a
distinction between user-oriented and system-oriented criteria. User-oriented criteria relate to the
behavior of the system as perceived by the individual user or process. An example is response
time in an interactive system. Response time is the elapsed time between the submission of a
request until the response begins to appear as output. This quantity is visible to the user and is
naturally of interest to the user. We would like a scheduling policy that provides “good” service
to various users. In the case of response time, a threshold may be defined, say two seconds. Then
a goal of the scheduling mechanism should be to maximize the number of users who experience
an average response time of two seconds or less.
Other criteria are system oriented. That is, the focus is on effective and efficient utilization of the
processor. An example is throughput, which is the rate at which processes are completed. This is
certainly a worthwhile measure of system performance and one that we would like to maximize.
However, it focuses on system performance rather than service provided to the user. Thus,
throughput is of concern to a system administrator but not to the user population.
Whereas user-oriented criteria are important on virtually all systems, system-oriented criteria are
generally of minor importance on single-user systems. On a single-user system, it probably is not
important to achieve high processor utilization or high throughput as long as the responsiveness
of the system to user applications is acceptable.
Another dimension along which criteria can be classified is those that are performance related
and those that are not directly performance related. Performance related criteria are quantitative
and generally can be readily measured. Examples include response time and throughput. Criteria
that are not performance related are either qualitative in nature or do not lend themselves readily
to measurement and analysis. An example of such a criterion is predictability. We would like for
the service provided to users to exhibit the same characteristics over time, independent of other
work being performed by the system. To some extent, this criterion can be measured by
calculating variances as a function of workload. However, this is not nearly as straightforward as
measuring throughput or response time as a function of workload.
The table below, summarizes key scheduling criteria. These are interdependent, and it is
impossible to optimize all of them simultaneously. For example, providing good response time
may require a scheduling algorithm that switches between processes frequently.
Scheduling Criteria
This increases the overhead of the system, reducing throughput. Thus, the design of a scheduling
policy involves compromising among competing requirements; the relative weights given the
various requirements will depend on the nature and intended use of the system. In most
interactive operating systems, whether single user or time shared, adequate response time is the
critical requirement.

Alternative Scheduling Policies


Table below presents some summary information about the various scheduling policies that are
examined in this subsection. The selection function determines which process, among ready
processes, is selected next for execution. The function may be based on priority, resource
requirements, or the execution characteristics of the process. In the latter case, three quantities
are significant:
w = time spent in system so far, waiting
e = time spent in execution so far
s = total service time required by the process, including e; generally, this quantity
must be estimated or supplied by the user
For example, the selection function max[w] indicates an FCFS discipline.

Characteristics of Various Scheduling Policies


Example of Process Scheduling

Process Scheduling

Definition
The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular
strategy. It is an essential part of a Multiprogramming operating systems. Such operating
systems allow more than one process to be loaded into the executable memory at a time and the
loaded process shares the CPU using time multiplexing.

The Process Scheduler schedule different processes to be assigned to the CPU based on
particular scheduling algorithm.
There are six popular process scheduling algorithms which we are going to discuss in the
following section:
 First-Come, First-Served (FCFS) Scheduling
 Shortest-Job-Next (SJN) Scheduling
 Priority Scheduling
 Shortest Remaining Time
 Round Robin (RR) Scheduling
 Multiple-Level Queues Scheduling

These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are


designed so that once a process
enters the running state, it cannot be preempted until it completes its allotted time whereas the
preemptive scheduling is
based on priority where a scheduler may preempt a low priority running process anytime when a
high priority process
enters into a ready state.

First Come First Serve (FCFS)


The simplest scheduling policy is first-come-first served (FCFS), also known as first-in-first-out
(FIFO) or a strict queueing scheme. Jobs are executed on first come, first serve basis. It is a non-
preemptive scheduling algorithm. Easy to understand and implement. Poor in performance as
average wait time is high. As each process becomes ready, it joins the ready queue. When the
currently running process ceases to execute, the process that has been in the ready queue the
longest is selected for running.
FCFS performs much better for long processes than short ones. Consider the following example

The normalized turnaround time for process Y is way out of line compared to the other
processes: the total time that it is in the system is 100 times the required processing time. This
will happen whenever a short process arrives just after a long process. On the other hand, even in
this extreme example, long processes do not fare poorly. Process Z has a turnaround time that is
almost double that of Y, but its normalized residence time is under 2.0.
Another difficulty with FCFS is that it tends to favor processor-bound processes over I/O-bound
processes. Consider that there is a collection of processes, one of which mostly uses the
processor (processor bound) and a number of which favor I/O (I/O bound). When a processor-
bound process is running, all of the I/O bound processes must wait. Some of these may be in I/O
queues (blocked state) but may move back to the ready queue while the processor-bound process
is executing. At this point, most or all of the I/O devices may be idle, even though there is
potentially work for them to do. When the currently running process leaves the Running state,
the ready I/O-bound processes quickly move through the Running state and become blocked on
I/O events. If the processor-bound process is also blocked, the processor becomes idle.
Thus, FCFS may result in inefficient use of both the processor and the I/O devices. FCFS is not
an attractive alternative on its own for a uniprocessor system. However, it is often combined with
a priority scheme to provide an effective scheduler.
Thus, the scheduler may maintain a number of queues, one for each priority level, and dispatch
within each queue on a first-come-first-served basis. We see one example of such a system later,
in our discussion of feedback scheduling.
Example 2:

Wait time of each process is following:

Average Wait Time: (0+4+6+13) / 4 = 5.75

Shortest Job Next (SJN)


This is also known as shortest job first, or SJF This is a non-preemptive scheduling algorithm.
Best approach to minimize waiting time. Easy to implement in Batch systems where required
CPU time is known in advance. Impossible to implement in interactive systems where required
CPU time is not known.
Processer should know in advance how much time process will take.

Wait time of each process is following:


Wait time of each process is following:

Average Wait Time: (3+0+14+5) / 4 = 5.50

Priority Based Scheduling


Priority scheduling is a non-preemptive algorithm and one of the most common scheduling
algorithms in batch systems.
Each process is assigned a priority. Process with highest priority is to be executed first and so on.
Processes with same priority are executed on first come first serve basis.
Priority can be decided based on memory requirements, time requirements or any other resource
requirement.
Wait time of each process is following

Average Wait Time: (9+5+12+0) / 4 = 6.5

Shortest Remaining Time


Shortest remaining time (SRT) is the preemptive version of the SJN algorithm. The processor is
allocated to the job closest to completion but it can be preempted by a newer ready job with
shorter time to completion.
Impossible to implement in interactive systems where required CPU time is not known. It is
often used in batch environments where short jobs need to give preference.

Round Robin Scheduling


A straightforward way to reduce the penalty that short jobs suffer with FCFS is to use
preemption based on a clock. Round Robin is the preemptive process scheduling algorithm. Each
process is provided a fix time to execute called quantum. Once a process is executed for given
time period. Process is preempted and other process executes for given time period. Context
switching is used to save states of preempted processes. The simplest such policy is round robin.
A clock interrupt is generated at periodic intervals. When the interrupt occurs, the currently
running process is placed in the ready queue, and the next ready job is selected on a FCFS basis.
This technique is also known as time slicing, because each process is given a slice of time before
being preempted.
With round robin, the principal design issue is the length of the time quantum, or slice, to be
used. If the quantum is very short, then short processes will move through the system relatively
quickly. On the other hand, there is processing overhead involved in handling the clock interrupt
and performing the scheduling and dispatching function. Thus, very short time quanta should be
avoided. One useful guide is that the time quantum should be slightly greater than the time
required for a typical interaction or process function. If it is less, then most processes will require
at least two time quanta.
Round robin is particularly effective in a general-purpose time-sharing system or transaction
processing system. One drawback to round robin is its relative

Wait time of each process is following:

Average Wait Time: (9+2+12+11) / 4 = 8.5

Multiple-Level Queues Scheduling


Multiple-level queues is not an independent scheduling algorithm but it makes use of other
existing algorithms to group and schedule jobs with common characteristic. Multiple queues are
maintained for processes with common characteristic. Each queue can have its own scheduling
algorithms. Priorities are assigned to each queue.
For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in another
queue. The Process Scheduler then alternately selects jobs from each queue and assign them to
the CPU based on the algorithm assigned to the queue.

You might also like