Beruflich Dokumente
Kultur Dokumente
Operating
Systems
Dr Damitha Kar u naratna
Univer s ity of Colombo school of computing
Topics to discuss
What is an operating system(OS)?
Main objectives of an OS
Main functions of an OS
Evolution of OS.
Process management.
Context switching.
Process state diagrams
Operating Systems
Operating Systems
Different types of
Software
Application Software
Systems Software
Operating system
System utilities
The quality of system software also
directly affects the application software
Operating Systems
Types of Software
Utility software:
system software
designed to help analyze,
configure, optimize or
maintain a computer
(Anti-virus, Backup
software, Editors, Data
compression, Disk
cleaners .).
They are not essential to
the running of the
computer
Transient
Component
Operating Systems
Operating Systems
Operating Systems
Execution of source
programs
Operating Systems
Operating Systems
10
Operating Systems
11
12
Operating Systems
13
Operating Systems
14
Main objectives of an
OS
Convenience: Make the computer more
convenient to use
Provide easy to use interface for a normal users.
Hide the complexity of the hardware devices from
the application developer.
Operating Systems
15
Services provided by an
OS
Process Management
Storage (external) management
Memory management
I/O device management
Management of the File System
Networking
User Interface
Protection
Operating Systems
16
Services provided by an
OS.
Error detection and response
Hardware errors: memory error or device
failure
Software errors: arithmetic errors, access
forbidden memory locations
Accounting
collect statistics (billing)
monitor performance
Operating Systems
17
Operating Systems
18
Operating Systems
19
OS and Processors
Can any OS run on any
processor?
Operating systems are software
Operating systems are designed
and developed for a specific CPU
family.
Macintosh OS: Motorola 680xx,
PowerPC Gx, Intel
DOS: Intel CPUs
Windows 9x and XP: Intel
80386, 80486, and Pentium CPUs
Linux: Intel CPUs
MS NT & 2000: Intel CPUs
Operating Systems
20
Compatibility of
Software
Question
Will software developed for one
operating system work on another?
For example will MS Word for
Macintosh run on a PC with
Windows XP?
Operating Systems
21
Compatibility of
Software
Question
Will software developed for one operating
system work on another?
Answer
No (unless there is special emulation
software or hardware). The software is
typically developed separately for each
operating system.
Operating Systems
22
Operating Systems
Disadvantages :
Scheduling: Hardcopy sigh-up sheet for
reserving time
User could reserve for 45 mins and
finish in 30 mins => wastage of time
User may not be able to finish in
scheduled time
23
Operating Systems
24
Operating Systems
25
Operating Systems
26
27
Operating Systems
28
Operating Systems
29
Operating Systems
30
Multiprogramming
Running multiple programs at the same
time
Requires sharing the CPU among multiple
processes
Firefox
Word
javac
Firefox
Word
31
Multiprogramming
Why multiprogramming?
Single user cannot keep CPU and I/O
devices busy at all times.
Multiprogramming organizes jobs (code
and data) so CPU always has one to
execute.
A subset of total jobs in system is kept
in memory.
One job selected and CPU is give for
that job.
When it has to wait, OS switches to
another job.
Operating Systems
32
Multiprogramming
Operating Systems
33
Operating Systems
34
Operating Systems
35
36
Operating Systems
37
Gaining Control
The OS gets the control of the CPU when
either an external event or an internal event
occurs.
External Events
Character typed at the console
Completion of an I/O operation
Timer quantum allowed for a process
expires.
Internal Events
Division by zero,
System call issued by a program
Page Fault
Unauthorized memory access
38
Operating Systems
Interrupts
External events get the attention of the
CPU through Interrupts.
For example when a disk driver has
finished transferring the requested
data, it generates an interrupt to the
OS to inform the OS that the task is
over.
Interrupts occur asynchronously to the
ongoing activity of the processor. Thus
the times at which interrupts occur are
unpredictable.
Operating Systems
39
Interrupt Handlers
Interrupt Handlers : Code that get
executed when an interrupt
occurs.
Associated with each type of
interrupt there is a specific
program to handle that type of
interrupts Interrupt handler
(Interrupt service routine)
Operating Systems
40
Operating Systems
41
Processes
Process is a fundamental concepts in modern operating
systems.
It was first introduced by the designers of Multics
operating systems in the 1960s.
The programs that reside in main memory are absolutely
different from their counter-parts the program files on
hard disks or any other secondary storage devices.
Operating Systems
42
Operating Systems
43
Operating Systems
44
45
Operating Systems
46
Uniprocessor
Scheduling
Type of processes
I/O bound processes
Processor bound processes
Operating Systems
47
Uniprocessor
Scheduling
Types of Scheduling
Long-term scheduling(Job scheduling) : It determines
which programs are admitted to the system for
processing. Job scheduler selects processes from the
queue and loads them into memory for execution.
Process loads into the memory for CPU scheduling.
Medium-term scheduling : Medium term scheduling
is in charge of swapping processes between the
main memory and the secondary storage.
Short-term scheduling (low-level scheduling) :
Determines which ready process will be assigned the
CPU when it next becomes available.
Operating Systems
48
Scheduling Policies
Non-preemptive
Once a process is in the running state,
it will continue until it terminates or
blocks itself for I/O.
Preemptive
Currently running process may be
interrupted and moved to the Ready
state by the OS.
Allows for better service since any one
process cannot monopolize the
processor for very long
Operating Systems
49
Processor Scheduling
Assigning the processor to the processes.
Turnaround time : Time required for a particular process
to complete, from submission time to completion.
Response time : The time taken in an interactive program
from the issuance of a command to the commence of a
response to that command.
Throughput : Number of processes completed per unit
time. May range from 10 / second to 1 / hour depending
on the specific processes.
Waiting time : How much time a process spends in the
ready queue waiting its turn to get on the CPU.
Operating Systems
50
Long-term scheduling(Job
scheduling)
Determines which processes are admitted
to the system for processing
Controls the degree of multiprogramming
If more processes are admitted
better CPU usage
less likely that all processes will be
blocked
The long term scheduler may attempt to
keep a mix of processor-bound and I/Obound processes
Operating Systems
51
Medium-Term
Scheduling
Swapping decisions based on the need
to manage multiprogramming
Done by memory management software
Operating Systems
52
Logical view of
swapping
Operating Systems
53
Short-Term Scheduling
Determines which process is going to
execute next (also called CPU
scheduling)
The short term scheduler is known as
the dispatcher
Dispatching the CPU to the process
Operating Systems
54
Schedulers Comparison
Long Term
Scheduler
Short Term
Scheduler
Medium Term
Scheduler
Job Scheduler
CPU scheduler
Processes swapping
scheduler
Selects processes
from a pool and
loads them into the
memory for
execution
Selects those
processes which are
ready to execute for
dispatching
Provides lesser
control over the
degree of
multiprogramming
Speed is in between
(short and long
term schedulers)
55
Operating Systems
56
Operating Systems
57
Operating Systems
Long Term
Scheduler
Short Term
Scheduler
58
59
Context Switching
A context switch is the mechanism to store and restore the
state or context of a CPU in Process Control block so that a
process execution can be resumed from the same point at a
later time.
Using this technique a context switcher enables multiple
processes to share a single CPU. Context switching is an
essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one
process to execute another, the context switcher saves the
content of all processor registers for the process being removed
from the CPU, in its process control block.
Context switch time is pure overhead.
Context switching can significantly affect performance as
modern computers have a lot of general and status registers to
be saved.
Operating Systems
60
Context Switching
Operating Systems
61
Operating Systems
62
63
First-come-first served
scheduling
Each process joins the end of the Ready
queue.
When the current process ceases to
execute, the process waited the longest
time in the Ready queue is assigned the
CPU.
Operating Systems
64
Example - FCFS
Proce
ss
Arriv
al
Time
Service
Time
Finis
h
time
Turnarou
nd time
13
18
12
20
12
Operating Systems
Average Turnaround
time
= (3 + 7+ 9+ 12 +
12)/5
= 8.60
65
Operating Systems
66
Arriv
al
Time
Service
Time
Finis
h
time
Turnarou
nd time
15
11
20
14
11
Operating Systems
Average Turnaround
time
= (3 + 7+ 11+ 14 +
3)/5
= 7.60
67
FCFS - Issues
A short process may have to
wait a very long time before it
can execute
Favors CPU-bound processes
I/O processes have to wait
until CPU-bound process
completes
Operating Systems
68
Operating Systems
69
Queuing Diagram
Operating Systems
70
al
Time
Time
h
time
nd time
18
16
17
13
20
14
15
Operating Systems
time
= (4 + 16+ 13+ 14 +
7)/5
= 10.80
10
15
20
71
al
Time
Time
h
time
nd time
17
15
11
20
14
19
11
time
= ( 3+ 15+ 7+ 14 +
11)/5
= 10.00
Gantt Chart ?
Operating Systems
72
Priority Scheduling
Scheduler will always choose a process
of higher priority over one of lower
priority
Use multiple ready queues to represent
multiple levels of priority
Lower-priority may suffer starvation
Allow a process to change its priority based
on its age or execution history
Operating Systems
73
Priority Queuing
74
Threads
A thread is the smallest schedulable unit in a system
that can be managed independently by an operating
system. A thread can also be viewed as an execution
streams within a single process. Generally a thread
contained inside a process. It is possible to have
processes with one threads or processes with multiple
threads.
All threads of a process share common code, data, and
other resources, including CPU registers.
Allows multiple tasks to be performed simultaneously in a
single address space.
Context switching generates less overhead.
Operating Systems
75
Threads ..
Threads are very useful whenever a process has multiple
tasks to perform independently of the others.
For example in a word processor, a background thread
may check spelling of a document while a foreground
thread processes user keystrokes, while another thread
may automatically backs up the edited section
periodically.
Operating Systems
76
77