CA403 OperatingSystem Sybbaca
CA403 OperatingSystem Sybbaca
Operating System
Concepts
Operating System Definitions
⚫ Resource allocator – manages and
allocates resources.
⚫ Control program – controls the
execution of user programs and
operations of I/O devices .
⚫ Kernel – the one program running at
all times (all else being application
programs).
Operating System
Concepts
Mainframe Systems
⚫ Reduce setup time by batching
similar jobs
⚫ Automatic job sequencing –
automatically transfers control
from one job to another. First
rudimentary operating system.
⚫ Resident monitor
⚫ initial control in monitor
⚫ control transfers to job
⚫ when job completes control transfers
pack to monitor
Operating System
Concepts
Memory Layout for a Simple Batch System
Operating System
Concepts
Multiprogrammed Batch
Systems
Several jobs are kept in main memory at the same
time, and the CPU is multiplexed among them.
Operating System
Concepts
OS Features Needed for Multiprogramming
Operating System
Concepts
Time-Sharing Systems–Interactive Computing
Operating System
Concepts
Desktop Systems
⚫ Personal computers – computer system
dedicated to a single user.
⚫ I/O devices – keyboards, mice, display
screens, small printers.
⚫ User convenience and responsiveness.
⚫ Can adopt technology developed for
larger operating system’ often
individuals have sole use of computer
and do not need advanced CPU
utilization of protection features.
⚫ May run several different types of
operating systems (Windows,
MacOS, UNIX, Linux)
Operating System
Concepts
Parallel Systems
⚫ Multiprocessor systems with more than
on CPU in close communication.
⚫ Tightly coupled system – processors share
memory and a clock; communication usually
takes place through the shared memory.
⚫ Advantages of parallel system:
⚫ Increased throughput
⚫ Economical
⚫ Increased reliability
⚫ graceful degradation
⚫ fail-soft systems
Operating System
Concepts
Parallel Systems (Cont.)
⚫ Symmetric multiprocessing (SMP)
⚫ Each processor runs and identical
copy of the operating system.
⚫ Many processes can run at once
without performance
deterioration.
⚫ Most modern operating systems
support SMP
⚫ Asymmetric multiprocessing
⚫ Each processor is assigned a specific
task; master processor schedules and
allocated work to slave processors.
⚫ More common in extremely large
systems
Operating System
Concepts
Symmetric Multiprocessing Architecture
Operating System
Concepts
Distributed Systems
⚫ Distribute the computation among
several physical processors.
⚫ Loosely coupled system – each processor
has its own local memory; processors
communicate with one another through
various communications lines, such as
high-speed buses or telephone lines.
⚫ Advantages of distributed systems.
⚫ Resources Sharing
⚫ Computation speed up – load sharing
⚫ Reliability
⚫ Communications
Operating System
Concepts
Computer-System Architecture
Operating System
Concepts
Computer-System Operation
⚫ I/O devices and the CPU can execute
concurrently.
⚫ Each device controller is in charge of a
particular device type.
⚫ Each device controller has a local buffer.
⚫ CPU moves data from/to main memory
to/from local buffers
⚫ I/O is from the device to local buffer of
controller.
⚫ Device controller informs CPU that it has
finished
Operating System its operation by causing an
Concepts
Common Functions of Interrupts
⚫ Interrupt transfers control to the interrupt
service routine generally, through the
interrupt vector, which contains the
addresses of all the service routines.
⚫ Interrupt architecture must save the
address of the interrupted instruction.
⚫ Incoming interrupts are disabled while
another interrupt is being processed to
prevent a lost interrupt.
⚫ A trap is a software-generated interrupt
caused either by an error or a user request.
Operating System
Concepts
Interrupt Handling
Operating System
Concepts
I/O Structure
⚫ After I/O starts, control returns to user
program only upon I/O completion.
⚫ Wait instruction idles the CPU until the next
interrupt
⚫ Wait loop (contention for memory access).
⚫ At most one I/O request is outstanding at a
time, no simultaneous I/O processing.
⚫ After I/O starts, control returns to user
program without waiting for I/O
completion.
⚫ System call – request to the operating
system to allow user to wait for I/O
completion.
⚫ Device-status table contains entry for each
I/O device indicating its type, address, and
state.
⚫ Operating system indexes into I/O device
table to
determine device status and to modify table
entry to include interrupt.
Operating System
Concepts
Two I/O Methods
Synchronous Asynchrono
us
Operating System
Concepts
Device-Status
Table
Operating System
Concepts
Direct Memory Access Structure
⚫ Used for high-speed I/O devices able to
transmit information at close to
memory speeds.
⚫ Device controller transfers blocks of data
from buffer storage directly to main
memory without CPU intervention.
⚫ Only on interrupt is generated per block,
rather than the one interrupt per byte.
Operating System
Concepts
Storage Structure
⚫ Main memory – only large storage media that
the CPU can access directly.
⚫ Secondary storage – extension of main
memory that provides large nonvolatile
storage capacity.
⚫ Magnetic disks – rigid metal or glass
platters covered with magnetic recording
material
⚫ Disk surface is logically divided into tracks,
which are subdivided into sectors.
⚫ The disk controller determines the logical
Operating System
Concepts interaction between the device and the
Moving-Head Disk Mechanism
Operating System
Concepts
Storage Hierarchy
⚫ Storage systems organized in hierarchy.
⚫ Speed
⚫ Cost
⚫ Volatility
⚫ Caching – copying information into faster
storage system; main memory can be viewed
as a last cache for secondary storage.
Operating System
Concepts
Storage-Device Hierarchy
Operating System
Concepts
Caching
⚫ Use of high-speed memory to hold recently-
accessed data.
⚫ Requires a cache management policy.
⚫ Caching introduces another level in storage
hierarchy. This requires data that is
simultaneously stored in more than one
level to be consistent.
Operating System
Concepts
Migration of A From Disk to
Register
Operating System
Concepts
Hardware Protection
⚫ Dual-Mode
Operation
⚫ I/O Protection
⚫ Memory
Protection
⚫ CPU Protection
Operating System
Concepts
Process Concept
⚫ An operating system executes a
variety of programs:
⚫ Batch system – jobs
⚫ Time-shared systems – user
programs or tasks
⚫ Textbook uses the terms job and
process almost interchangeably.
⚫ Process – a program in execution;
process execution must progress in
sequential fashion.
⚫ A process includes:
⚫ program counter
⚫ stack
⚫ data section
Operating System
Concepts
Process State
⚫ As a process executes, it changes state
⚫ new: The process is being created.
⚫ running: Instructions are being
executed.
⚫ waiting: The process is waiting for some
event to occur.
⚫ ready: The process is waiting to be
assigned to a process.
⚫ terminated: The process has
finished execution.
Operating System
Concepts
Diagram of Process State
Operating System
Concepts
Process Control Block (PCB)
Information associated with each
process.
⚫ Process state
⚫ Program counter
⚫ CPU registers
⚫ CPU scheduling information
⚫ Memory-management
information
⚫ Accounting information
⚫ I/O status information
Operating System
Concepts
Process Control Block (PCB)
Operating System
Concepts
CPU Switch From Process to Process
Operating System
Concepts
Process Scheduling Queues
⚫ Job queue – set of all processes in the
system.
⚫ Ready queue – set of all processes
residing in main memory, ready and
waiting to execute.
⚫ Device queues – set of processes waiting
for an I/O device.
⚫ Process migration between the various
queues.
Operating System
Concepts
Ready Queue And Various I/O Device Queues
Operating System
Concepts
Representation of Process Scheduling
Operating System
Concepts
Schedulers
⚫ Long-term scheduler (or job scheduler) –
selects which processes should be brought
into the ready queue.
⚫ Short-term scheduler (or CPU scheduler) –
selects which process should be executed next
and allocates CPU.
Operating System
Concepts
Addition of Medium Term Scheduling
Operating System
Concepts
Schedulers (Cont.)
⚫ Short-term scheduler is invoked very
frequently (milliseconds) (must be
fast).
⚫ Long-term scheduler is invoked very
infrequently (seconds, minutes) (may
be slow).
⚫ The long-term scheduler controls the
degree of multiprogramming.
⚫ Processes can be described as either:
⚫ I/O-bound process – spends more time doing
I/O than computations, many short CPU
bursts.
⚫ CPU-bound process – spends more
Operating System
Concepts
Context Switch
⚫ When CPU switches to another process,
the system must save the state of the
old process and load the saved state for
the new process.
⚫ Context-switch time is overhead; the
system does no useful work while
switching.
⚫ Time dependent on hardware support.
Operating System
Concepts
Process Creation
⚫ Parent process create children processes,
which, in turn create other processes,
forming a tree of processes.
⚫ Resource sharing
⚫ Parent and children share all resources.
⚫ Children share subset of parent’s
resources.
⚫ Parent and child share no resources.
⚫ Execution
⚫ Parent and children execute concurrently.
⚫ Parent waits until children terminate.
Operating System
Concepts
Process Creation (Cont.)
⚫ Address space
⚫ Child duplicate of parent.
⚫ Child has a program loaded into it.
⚫ UNIX examples
⚫ fork system call creates new process
⚫ exec system call used after a fork to replace
the process’ memory space with a new
program.
Operating System
Concepts
Processes Tree on a UNIX System
Operating System
Concepts
Process Termination
⚫ Process executes last statement and asks the
operating system to decide it (exit).
⚫ Output data from child to parent (via wait).
⚫ Process’ resources are deallocated by operating
system.
⚫ Parent may terminate execution of children
processes (abort).
⚫ Child has exceeded allocated resources.
⚫ Task assigned to child is no longer required.
⚫ Parent is exiting.
⚫ Operating system does not allow child to continue if
its parent terminates.
⚫ Cascading termination.
Operating System
Concepts
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
Operating System
Concepts
Alternating Sequence of CPU And I/O Bursts
Operating System
Concepts
Histogram of CPU-burst Times
Operating System
Concepts
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 nonpreemptive.
⚫ All other scheduling is preemptive.
Operating System
Concepts
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
⚫ jumping to the proper location in the user
program to restart that program
⚫ Dispatch latency – time it takes for the
dispatcher to stop one process and start
another running.
Operating System
Concepts
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)
Operating System
Concepts
Optimization Criteria
⚫ Max CPU
utilization
⚫ Max throughput
⚫ Min turnaround
time
⚫ Min waiting time
⚫ Min response
time
Operating System
Concepts
First-Come, First-Served (FCFS) Scheduling
Process Burst
Time
P1 24
P2
⚫ Suppose that the processes 3
arrive in the order:
P1 , P2 , P3 P3 3
The Gantt Chart for the schedule is:
P1 P2 P3
Operating System
Concepts
FCFS Scheduling (Cont.)
Suppose that the processes arrive in
the order 2 3 1
t P2 orP3 P schedule
,P P1
chart the is:
0f 3 , P6 3
0
.
⚫ The Gant
⚫ Waiting time for P1 = 6; P2 = 0; P3 = 3
⚫ Average waiting time:(6 + 0 + 3)/3 = 3
⚫ Much better than previous case.
⚫ Convoy effect short process behind long
process
Operating System
Concepts
Shortest-Job-First (SJR) Scheduling
⚫ Associate with each process the length of its
next CPU burst. Use these lengths to schedule
the process with the shortest time.
⚫ Two schemes:
⚫ nonpreemptive – once CPU given to the process it
cannot be preempted until completes its CPU
burst.
⚫ preemptive – if a new process arrives with CPU
burst length less than remaining time of current
executing process, preempt. This scheme is
know as the
Shortest-Remaining-Time-First (SRTF).
⚫ SJF is optimal – gives minimum average waiting
time for a given set of processes.
Operating System
Concepts
Example of Non-Preemptive SJF
Process Arrival Time Burst
Time
P 0.
1
0 7
P 2. 4
2
0 14
⚫ SJF non-P P1 4.P3 P2 P4
( preemptive) 0
3
0 P 3 5.7 1 1
8 2 6
4
0
Operating System
Concepts