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

BX4003 Unit V

The document discusses process management topics like CPU scheduling, scheduling criteria and algorithms, threads and process synchronization. It covers concepts like critical section problem, semaphores, and classical synchronization problems.

Uploaded by

Anand Print
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)
315 views

BX4003 Unit V

The document discusses process management topics like CPU scheduling, scheduling criteria and algorithms, threads and process synchronization. It covers concepts like critical section problem, semaphores, and classical synchronization problems.

Uploaded by

Anand Print
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/ 27

lOMoARcPSD|30183744

UNIT V - Bridge course computer network II Semester Anna


University
Master of Computer Applications (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Yasar Arafath A ([email protected])
lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

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

 Maximum CPU utilization obtained with multiprogramming


 CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait.
 CPU burst distribution

Alternating Sequence of CPU And I/O Bursts


CPU Scheduler
 Selects from among the processes in memory that are ready to execute, and allocates the CPU
to one of them.
 CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
 Scheduling under 1 and 4 is non preemptive.
 All other scheduling is preemptive.
Dispatcher
Dispatcher module gives control of the CPU to the process selected by the short-term
scheduler; this involves:
✦ switching context
✦ switching to user mode
1 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

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 utilization – keep the CPU as busy as possible


 Throughput – # of processes that complete their execution per time unit
 Turnaround time – amount of time to execute a particular process
 Waiting time – amount of time a process has been waiting in the ready queue
 Response time – amount of time it takes from when a request was submitted until the first
response is produced, not output (for time-sharing environment)

Optimization Criteria

 Max CPU utilization


 Max throughput
 Min turnaround time
 Min waiting time
 Min response time

CPU Scheduling Algorithm:

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

3 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

4 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

===========================================================================

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.

Critical Section Problem:


Consider a system consisting of n processes (P0 , P1 , ………Pn -1)

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

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--;
}

The classical definition of the signal is

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.

Binary Semaphores S1, S2;

int C;

6 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

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
);

The signal operation of the binary semaphore can be implemented as follows:

Wait (S1);
C++;
if (C <=0)
Signal (S2);
Else
Signal (S1);

7 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

Classical Problem on Synchronization:

There are various types of problem which are proposed for synchronization scheme such as

8 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

9 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

10 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

11 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

12 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

------------------------------------------------------------------end-----------------------------------------

13 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)


Critical Region:
According to the critical section problem using semaphore all processes must share a semaphore Variable
mutex which is initialized to one. Each process must execute wait (mutex) before entering the critical section
and execute the signal (mutex) after completing the execution but there are various difficulties may arise
with this approach like:

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

16 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

17 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

19 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

20 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

21 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

Implements the one-to-one mapping, kernel-level


Each thread contains
 A thread id
 Register set
 Separate user and kernel stacks
 Private data storage area
 The register set, stacks, and private storage area are known as the context of the threads
 The primary data structures of a thread include:
 ETHREAD (executive thread block)
 KTHREAD (kernel thread block)
 TEB (thread environment block)

22 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

----------------------------------------------------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:

There are 3 types of schedulers mainly used:

23 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

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

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

Difference between process & program:

A program by itself is not a process. A program in execution is known as a process. A program is a


passive entity, such as the contents of a file stored on disk where as process is an active entity with a
program counter specifying the next instruction to execute and a set of associated resources may be
shared among several process with some scheduling algorithm being used to determinate when the
stop work on one process and service a different one.
Process state: As a process executes, it changes state. The state of a process is defined by the
correct activity of that process. Each process may be in one of the following states.
• New: The process is being created.
• Ready: The process is waiting to be assigned to a processor.
• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur.
• Terminated: The process has finished execution.
Many processes may be in ready and waiting state at the same time. But only one process can be
running on any processor at any instant

25 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])


lOMoARcPSD|30183744

BX4003---------- INTRODUCTION TO COMPUTER ORGANIZATION AND OPERATING SYSTEM (BRIDGE COURSE)

-----------------------------------------------------------------------------------------------------------------------------

26 UNIT V ----- PROCESS MANAGEMENT ---- ---- I YEAR/II SEM ******* MCA

Downloaded by Yasar Arafath A ([email protected])

You might also like