BX4003 Unit V
BX4003 Unit V
PROCESS MANAGEMENT
CPU Scheduling – Scheduling criteria, Scheduling algorithms, Multiple-processor
scheduling, Threads Overview– The critical-section problem, Semaphores, Classical
problems of synchronization, Critical regions
===================================================
=============
CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Real-Time Scheduling
Algorithm Evaluation
Basic Concepts
BX4003----------
✦ jumpingINTRODUCTION
to the properTO COMPUTER
location ORGANIZATION
in the AND
user program OPERATING
to restart that SYSTEM
program(BRIDGE COURSE)
Dispatch latency – time it takes for the dispatcher to stop one process and start another running.
Scheduling Criteria
CPU Scheduling deals with the problem of deciding which of the processes in the ready queue is to be
allocated first to the CPU. There are four types of CPU scheduling that exist.
2 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
3 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
4 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
===========================================================================
Process Synchronization:
A co-operation process is one that can affect or be affected by other processes executing in the system. Co-operating
process may either directly share a logical address space or be allotted to the shared data only through files. This
concurrent access is known as Process synchronization.
Each process has a segment of code which is known as critical section in which the process may be changing
common variable, updating a table, writing a file and so on.
The important feature of the system is that when the process is executing in its critical section no other
process is to be allowed to execute in its critical section. The execution of critical sections by the processes is a
mutually exclusive.
The critical section problem is to design a protocol that the process can use to cooperate each process must
request permission to enter its critical section. The section of code implementing this request is the entry section.
The critical section is followed on exit section. The remaining code is the remainder section.
Example:
While (1)
Entry Section;
Critical Section;
Exit Section;
Remainder Section;
A solution to the critical section problem must satisfy the following three conditions.
1. Mutual Exclusion: If process Pi is executing in its critical section then no any other process
5 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
BX4003----------
can be executing INTRODUCTION TO COMPUTER
in their critical section. ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)
2. Progress: If no process is executing in its critical section and some process wish to enter their critical
sections then only those process that are not executing in their remainder section can enter its critical section
next.
3. Bounded waiting: There exists a bound on the number of times that other processes are allowed to enter
their critical sections after a process has made a request
=============================================================================
Semaphores:
For the solution to the critical section problem one synchronization tool is used which is known as semaphores. A
semaphore ‘S’ is an integer variable which is accessed through two standard operations such as wait and signal.
These operations were originally termed ‘P’ (for wait means to test) and ‘V’ (for single means to increment).
The classical definition of wait is
Wait (S)
{
While (S <= 0)
{
Test;
}
S--;
}
Signal (S)
S++;
In case of wait the test condition is executed with interruption and the decrement is executedwithout
interruption.
Binary Semaphore:
A binary semaphore is a semaphore with an integer value which can range between 0 and 1.
Let ‘S’ be a counting semaphore. To implement the binary semaphore we need following the structure of
data.
int C;
6 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
BX4003----------
Initially INTRODUCTION
S1= 1, S2 =TO COMPUTER
0 and ORGANIZATION
the value of C is set AND
to theOPERATING SYSTEM
initial value of the(BRIDGE COURSE)
counting semaphore
‘S’.Then the wait operation of the binary semaphore can be implemented as follows.
Wait (S1)
C--;
if (C < 0)
{
Signal (S1);
Wait (S2);
}
Signal (S1
);
Wait (S1);
C++;
if (C <=0)
Signal (S2);
Else
Signal (S1);
7 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
There are various types of problem which are proposed for synchronization scheme such as
8 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
9 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
10 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
11 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
12 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
------------------------------------------------------------------end-----------------------------------------
13 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
Case 1: Suppose that a process interchanges the order in which the wait and signal operations onthe
semaphore mutex are executed, resulting in the following execution:
Signal (mutex);
..........
Critical Section
...........
Wait (mutex);
In this situation several processes may be executing in their critical sections simultaneously, which is
violating mutual exclusion requirement.
Case 2: Suppose that a process replaces the signal (mutex) with wait (mutex). The execution is as follows:
Wait (mutex);
...........
Critical Section
...........
Wait (mutex);
In this situation a deadlock will occur
Case 3: Suppose that a process omits the wait (mutex) and the signal (mutex). In this case the
mutual exclusion is violated or a deadlock will occur.
To illustrate the various types or error generated by using semaphore there are some high level language
constructs have been introduced such as critical region and monitor.
Critical region is also known as conditional critical regions. It constructs guards against certain simple errors
associated with semaphore. This high level language synchronization construct requires a variable V of type
T which is to be shared among many processes. It is declared as
V: shared T;
The variable V can be accessed only inside a region statement as like below:
14 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
Else
Signal (mutex);
(Implementation of the conditional region constructs)
Where B is a Boolean variable which governs the access to the critical regions which is initialized to false.
Mutex, First_delay and Second_delay are the semaphores which are initialized to 1, 0, and 0 respectively.
First_count and Second_count are the integer variables which are initialized to zero.
15 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
16 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
17 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
Linux Scheduling
Constant order O(1) scheduling time
Two priority ranges: time-sharing and real-time
Real-time range from 0 to 99 and nice value from 100 to 140
-------------------------------------------------------------END---------------------------------------------------------------
18 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
19 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
20 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
21 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
22 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
----------------------------------------------------END--------------------------------------------------------
====================================================================
SCHEDULERS:
A process migrates between the various scheduling queues throughout its life-time purposes. The OS
must select for scheduling processes from these queues in some fashion. This selection process is carried out
by the appropriate scheduler. In a batch system, more processes are submitted and then executed
immediately. So these processes are spooled to a mass storage device like disk, where they are kept for later
execution.
Types of schedulers:
23 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
BX4003----------
1. Long termINTRODUCTION TO COMPUTER
scheduler: Long ORGANIZATION
term scheduler selectsAND OPERATING
process SYSTEM
from the (BRIDGE
disk & loadsCOURSE)
them into memory for
execution. It controls the degree of multi-programming i.e. no. of processes in memory. It executes less
frequently than other schedulers. If the degree of multiprogramming is stable than the average rate of process
creation is equal to the average departure rate of processes leaving the system. So, the long term scheduler is
needed to be invoked only when a process leaves the system. Due to longer intervals between executions it
can afford to take more time to decide which process should be selected for execution.
Most processes in the CPU are either I/O bound or CPU bound. An I/O bound process (an interactive
‘C’ program is one that spends most of its time in I/O operation than it spends in doing I/O operation. A CPU
bound process is one that spends more of its time in doing computations than I/O operations (complex
sorting program). It is important that the long term scheduler should select a good mix of I/O bound & CPU
bound processes.
2. Short - term scheduler: The short term scheduler selects among the process that are ready to execute &
allocates the CPU to one of them. The primary distinction between these two schedulers is the frequency of
their execution. The short-term scheduler must select a new process for the CPU quite frequently. It must
execute at least one in 100ms. Due to the short duration of time between executions, it must be very fast.
3. Medium - term scheduler: some operating systems introduce an additional intermediate level of
scheduling known as medium - term scheduler. The main idea behind this scheduler is that sometimes it is
advantageous to remove processes from memory & thus reduce the degree of multiprogramming. At some
later time, the process can be re-introduced into memory & its execution can be continued from where
it had left off. This is called as swapping. The process is swapped out & swapped in later by medium term
scheduler.
Swapping is necessary to improve the process miss or due to some change in memory requirements, the
available memory limit is exceeded which requires some memory to be freed up.
------------------------------------------------------------------------------------------------------------------------------
24 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
25 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA
-----------------------------------------------------------------------------------------------------------------------------
26 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA