Big Data Part-1 Operating System
Big Data Part-1 Operating System
Operating Systems
Operating
system
OS Road Map
Concepts
+
Process
synchronization
+
Processes& +
Threads
+
CPU
Scheduling
+
Memory
©Ahmed Hagag Operating Systems Management
2
Reference
Computer Operating System Concepts
• Author: Silberschatz
• Publisher: Wiley
• Edition: Sixth
• ISBN: 0471250600
(OS)
System Concepts
• Operating System
• Single processor
• Multiprocessor Systems
• Distributed Systems
• Clustered System
• Real -Time Systems
• Handheld Systems
Operating System
• What is an Operating System?
• It acts as an intermediary between a user and his hardware
• Operating system objective
• Executes users programs
• Solves its problems
Operating System
• It controls and coordinates the use of the HW among the various
application programs for the various users
• It manages and allocates resources
• It controls the execution of user programs and operations of I/O devices
• Kernel – the one program running at all times
Mainframe Systems
• Reduce setup time by batching similar jobs
• Automatic job sequencing
• Automatically transfers control from one job to another.
• First rudimentary operating system
Single processor
• Memory Layout for a Simple Batch System
Single processor
• Multi-programmed Batch Systems
• Several jobs are kept in main memory at the same time, and the CPU is
multiplexed among them
• OS features needed
• I/O routine supplied by the system
• Memory management
• The system must allocate the memory
to several jobs
• CPU scheduling
• The system must choose among
several jobs ready to run
Single processor
storage
standby
• OS is a control program
➢ Controls execution of programs to prevent errors and improper
use of the computer.
• It shares with other threads belonging to the same process its code section,
data section, and other operating-system resources, such as open files and
signals.
©Ahmed Hagag Operating Systems 48
Introduction
• Let's say, for example, a program is not capable of drawing pictures while
reading keystrokes. The program must give its full attention to the
keyboard input lacking the ability to handle more than one event at a time.
• The ideal solution to this problem is the seamless execution of two or more
Schedulers
• Long-term scheduler chooses some of them to go to memory
(ready queue).
• Then, short-term scheduler (or CPU scheduler) chooses from
ready queue a job to run on CPU.
• Medium-term scheduler may move (swap) some partially-
executed jobs from memory to disk (to enhance performance).
CPU Scheduler
• 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.
Note: A process may have many CPU bursts, but in the following
examples we show only one for simplicity.
P1
0
P1
0
P1
0
P1
0
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1
0
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
0 24 27
P1
0
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1
0
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
24 27 30
P1
0
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1
0
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
0 24 27
P2 P3 P
0
P2 P3 P
0
P2 P3 P
0
P2 P3 P
0
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P2 P3 P
0
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
6 0 3
P2 P3 P
0
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P2 P3 P
0
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
30 3 6
P2 P3 P
0
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P2 P3 P
0
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
6 0 3
P4 P1 P3 P2
0 3 9 16 24
P4 P1 P3 P2
0 3 9 16 24
P4 P1 P3 P2
0 3 9 16 24
P4 P1 P3 P2
0 3 9 16 24
P4 P1 P3 P2
0 3 9 16 24
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P4 P1 P3 P2
0 3 9 16 24
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
3 16 9 0
P4 P1 P3 P2
0 3 9 16 24
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P4 P1 P3 P2
0 3 9 16 24
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
9 24 16 3
P4 P1 P3 P2
0 3 9 16 24
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P4 P1 P3 P2
0 3 9 16 24
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
3 16 9 0
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P4 P1
P3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 5 10 17
2
6
Can be done by using the length of previous CPU bursts, using exponential
averaging
1. t n = actual length of n th CPU burst
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 2 3 5 10 17
26
P1 P2 P4 P1
P3
0 1 2 3 5 10 17 26
P1 P2 P4 P1
P3
0 1 2 3 5 10 17 26
P1 P2 P4 P1
P3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 5 10 17
2
6
P1 P2 P4 P1 P
3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P4 P1 P3
0 1 5 10 17 26
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P1 P2 P4 P1 P3
0 1 5 10 17 26
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
10 − 1 1−1 17 − 2 5−3
= 𝟗 = 𝟎 = 𝟏𝟓 = 𝟐 Average waiting time = [9+0+15+2]/4 = 26/4 = 6.5 msec
©Ahmed Hagag Operating Systems 131
Scheduling Algorithms
2.2 Shortest-remaining-time-first (Preemptive SJF )
Process Arrival Time Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Preemptive SJF Gantt Chart
P1 P2 P4 P1 P3
0 1 5 10 17 26
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P1 P2 P4 P1 P3
0 1 5 10 17 26
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
17 − 0 5−1 26 − 2 10 − 3
= 𝟏𝟕 = 𝟒 = 𝟐𝟒 = 𝟕 Average turnaround time = [17+4+24+7]/4 = 52/4 = 13 msec
P1 P2 P4 P1 P3
0 1 5 10 17 26
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
P1 P2 P4 P1 P3
0 1 5 10 17 26
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒
0−0 1−1 17 − 2 5−3
= 𝟎 = 𝟎 = 𝟏𝟓 = 𝟐 Average response time = [0+0+15+2]/4 = 17/4 = 4.25 msec
The CPU is allocated to the process with the highest priority (smallest integer
highest priority)
Preemptive
Nonpreemptive
SJF is priority scheduling where priority is the inverse of predicted next CPU
burst time
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
6 0 16 18 1 Average Waiting time = [6+0+16+18+1]/5 = 8.2 msec
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
16 1 18 19 6 Average Turnaround time = [16+1+18+19+6]/5 = 12 msec
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑 𝑷𝟒 𝑷𝟓
6 0 16 18 1 Average Response time = [6+0+16+18+1]/5 = 8.2 msec
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
# of context switches = ??
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
# of context switches = 7
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Waiting Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
0 + (10 − 4) 4 7
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Turnaround Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
30 7 10
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Response Time
𝑷𝟏 𝑷𝟐 𝑷𝟑
0 4 7
𝑄0
𝑄1
𝑄2
7ms
7ms
𝑄0 𝑃1
𝑄1
𝑄2
7ms
7ms 8ms
𝑄0 𝑃1 𝑃2
𝑄1
𝑄2
15ms
7ms 8ms
𝑄0 𝑃1 𝑃2
𝑄1
𝑄2
15ms
7ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3
𝑄1 𝑃2
𝑄2
23ms
7ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3
𝑄1 𝑃2
𝑄2
23ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
𝑄1 𝑃2
𝑄2
31ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms
𝑄1 𝑃2
𝑄2
31ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms
𝑄1 𝑃2 𝑃3
36ms
𝑄2 𝑃2
43ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms
𝑄1 𝑃2 𝑃3
36ms
𝑄2 𝑃2
43ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms 16ms
𝑄1 𝑃2 𝑃3 𝑃4
36ms
𝑄2 𝑃2
59ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms 16ms
𝑄1 𝑃2 𝑃3 𝑃4
36ms
𝑄2 𝑃2
67ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms 16ms
𝑄1 𝑃2 𝑃3 𝑃4
36ms
𝑄2 𝑃2
67ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms 16ms
𝑄1 𝑃2 𝑃3 𝑃4
36ms 16ms
𝑄2 𝑃2 𝑃4
83ms
7ms 8ms 8ms 8ms
𝑄0 𝑃1 𝑃2 𝑃3 𝑃4
16ms 12ms 16ms
𝑄1 𝑃2 𝑃3 𝑃4
36ms 16ms
𝑄2 𝑃2 𝑃4
𝑄0
𝑄1
𝑄2
7ms
7ms
𝑄0 𝑃1
𝑄1
𝑄2
7ms
7ms
𝑄0 𝑃1
𝑄1
𝑄2
𝑄1
𝑄2
𝑄1
𝑄2
𝑄1
𝑄2
𝑄2
𝑄2
𝑄2
𝑄2