Operating Systems Unit-1: Tribhuvan Singh (GLA120252) Assistant Professor
Operating Systems Unit-1: Tribhuvan Singh (GLA120252) Assistant Professor
1 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Table of Contents
1 Syllabus
2 Introduction
3 OS Classification
5 Process Concept
6 CPU Scheduling
7 Process Synchronization
2 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Syllabus Module-1
3 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
4 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
5 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
7 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Advantages:
It saves the time that was being wasted earlier for each
individual process in context switching from one environment
to another environment.
No manual intervention is needed.
8 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Disadvantages:
Priority can not be set for the jobs.
Batch operating system may lead to starvation.
CPU may remain idle for a long time.
There is a lack of interaction between a user and his job.
9 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
10 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
11 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
12 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
13 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Layered Structure
14 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Layered Structure
16 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
PCB Cont...
18 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
19 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
20 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
CPU Scheduling
21 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
23 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
24 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
25 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
FCFS Cont...
If the arrival time of the process are matching then scheduled the
process which has lowest process number (process ID).
use FCFS to calculate average TAT, average WT, average RT for
the following data.
Pr No. AT BT
P1 8 4
P2 3 2
P3 7 6
P4 10 3
P5 2 1
P6 3 1
26 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
27 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
28 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
If the burst time of the processes are same then schedule the
process which has lowest arrival time.
Consider SJF-non-Preemptive to calculate average TAT, average
WT, average RT.
Pr. No. AT BT
P1 6 1
P2 3 3
P3 4 6
P4 1 5
P5 2 2
P6 5 1
29 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
30 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
31 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
32 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
33 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
34 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Process Synchronization
35 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Producer:
while (true)
int item p;
while (counter == N) ; /* do nothing */
buffer[in] = item p;
in = (in + 1)mod N;
counter++;
36 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Consumer:
while (true)
while (counter == 0); /* do nothing */
next consumed = buffer[out];
out = (out + 1)mod N;
counter–;
37 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
38 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
39 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Dekker’s Solution
40 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Peterson’s Solution
41 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Semaphore
42 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Types of Semaphore
43 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Operations in Semaphore
44 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Down (Semaphore S)
{
S.value = S.value - 1;
if (S.value <0 )
{
block the process and place its PCB in the suspended list ();
}
}
45 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Up (Semaphore S)
{
S.value = S.value + 1;
if (S.value ≤ 0 )
{
Select a process from suspended list () and wakup();
}
}
46 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
47 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Down (Semaphore S)
{
if (S.value = = 1 )
S.value = 0;
else
{
Block the process and place its PCB in the suspended list();
}
}
48 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Up (Semaphore S)
{
if (suspended list () is empty)
S.value = 1;
else
{
select a process from suspended list() and wakup();
}
}
49 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
50 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
X Y Z
P(a) P(b) P(c)
P(b) P(c) P(d)
P(c) P(d) P(a)
51 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Solution contt...
B:
X Y Z
P(b) P(b) P(a)
P(a) P(c) P(c)
P(c) P(d) P(d)
C:
X Y Z
P(b) P(c) P(a)
P(a) P(b) P(c)
P(c) P(d) P(d)
52 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Solution contt...
D:
X Y Z
P(a) P(c) P(c)
P(b) P(b) P(d)
P(c) P(d) P(a)
53 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Reader-Writer Problem
Writer Reader
wait (wrt) wait (mutex)
write operation readcount++
signal (wrt) if (readcount==1)
wait (wrt)
signal(mutex)
read operation
wait(mutex)
readcount–
if (readcount==0)
signal(wrt)
signal(mutex)
54 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
55 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
1 1 1 1 1
56 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Synchronization Hardware
1. TSL Ri , flag
2. CMP Ri , # 0
3. JNZ to step 1
4. Critical Section
5. Store flag, # 0
57 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
Principle of Concurrency
58 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
59 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
60 / 60
Syllabus Introduction OS Classification Operating Systems Structure Process Concept CPU Scheduling Process Synchroniza
60 / 60