Operating Systems Course Overview
Operating Systems Course Overview
STAFF NAME :
CLASS : III BCA
SUBJECT : OPERATING SYSTEMS
SUBJECT CODE :
1
1. Recommended Texts
th
(i) A. Silberschatz P.B. Galvin, Gange, 2002, Operating System Concepts, 6
Edn., AddisonWesley Publishing Co., Boston.
OPERATING SYSTEMS
UNIT – 1
OPERATING SYSTEM
Operating System
Computer
Hardware
2
VIEWS OF AN OPERATING SYSTEMS
3
System point of view :
TYPES OF SYSTEMS
4
The OS can be classifieds into several types. They are explained below.
OS
User
Program
Area
5
the disk as a huge before for reading and writing.
● Spooling is also used for processing data at remote sites (ex:
Printer)
● Spooling Overlaps the I/O of one job with computation of other jobs.
● Spooling increases performance of the system.
.
.
.
6
Job n
● If several jobs are ready to run at the same time, the system must
choose among them, this decision making is
called CPU SCHEDULING.
● Here throughput is increased.
● The User cannot interact while running a program.
7
among several processors
● Each processor has its own local memory.
● These processors communicate with one another through various
communication lines, such as High-speed
buses or telephone lines.
● The processors may vary in size and function.
● This may include small microprocessor, workstation, mini
computers and large general purpose computer
systems.
● These processors are referred by different names such as sites,
nodes, and computers and so on.
● There are some reasons for building Distributed Systems. They are
given below.
Resource Sharing
Computation Speedup
Reliability
Communication
8
Some display systems.
Automobile-engine fuel-injection systems.
Home appliance controllers.
Weapon system.
● The real time OS has well-defined, fixed time constraints.
● Processing must be done within the defined constraints or the
system will fail.
● There are two types of real time OS.
1. Hard real time OS guaranties that the critical tasks complete on
time.
2. Soft real time OS, the critical task gets priority over other tasks, and
retains the priority until it completes.
vi. Parallel or Multiprocessor or Tightly coupled Systems.
● It has more than one processor in close communication.
● Sharing the computer bus, the clock, memory and peripheral
devices.
● We are using shared memory for all
● The Reasons for building parallel system are given below.
Speedup.
Resource sharing
Increase reliability
● It has two types.
1. Symmetric Multiprocessing
● Most commonly used Multiprocessing OS.
● Each processor runs on identical copy of the OS.
● These copies communicate with one another as needed.
2. Asymmetric Multiprocessing.
9
● Each processor is assigned a specific task.
● A Master processor controls the system.
● The other processor either look to the master for instruction or
have predefined tasks.
● The master processor schedules and allocates work to the
Slave processors.
10
address.
●It is a repository of quickly accessible data shared by the CPU & I/O
devices.
●The OS is responsible for the following activities in connection with
memory management
Keep track of which part of memory are currently being used
and by whom.
Decide which process is loaded into memory when memory
space becomes available.
Allocate and deallocate memory space as needed.
3. File Management
●A file is a collection of related information defined by creator.
●The OS is responsible for the following activities in connection with
memory management
The creation and deletion of files.
The creation and deletion of directories.
The support of primitives for manipulating files and directories.
The mapping of files onto secondary storage.
The back up of files on stable storage media.
4. I/O Management
●The OS is to hide the peculiarities of specific hardware device from
user.
●The I/O subsystem consists of the following.
A memory management component that includes Buffering,
Caching and Spooling.
A general device driver interface
Drivers for specific H/W devices.
11
5. Secondary – Storage Management
●The secondary storage is a backup of primary memory.
●The OS is responsible for the following activities in connection with
secondary storage management
Managing the free space available on the secondary-storage
device.
Allocation of storage space when new files have to be written.
Scheduling the requests for memory access.
6. Networking
●The number of computers interconnected together is called a
network.
●The network may be fully or partially connected.
●The design must consider the message routing and connection
strategies and the problems of connections and security.
7. Protection System
●Protection is any mechanism for controlling the access of
programs, processes or users to the resources defined by a
computer system.
●Protection can improve reliability by detecting errors at the
interfaces between component systems.
8. Command-Interpreter System
●It is one of the most important program for an OS.
●It is an interface between user and OS.
●Some OS includes it in the Kernel.
●Other OS (MS-DOS), UNIX) treat it as a special program.
●It is also sometimes called as control-card interpreter or shell.
12
OPERATING SYSTEM SERVICES
● An OS provides an environment for the execution of
programs.
● The Os provides certain services to programs and to
the users of those programs.
● These services are differing from one OS to another.
● But, there are some common services that we can
identify.
● These services are provided for the convenience of
the programmer, to make the programming task
easier.
1. Program Execution
● The OS must be able to LOAD a program into memory and run it.
● The program must be ending its execution either normally or
abnormally.
2. I/O operations.
● A running program may require I/O.
● This may involve a file or an I/O device.
● User cannot control I/O devices directly.
● The OS must provide some means of I/O.
3. File-System Manipulations.
● The files are created and deleted by OS using its names
● The file system should be read and write for programs.
4. Communication
● One process needs to exchange information with another process.
● There are two major ways for communication.
13
Communication between processes executing on the same
computer.
Communication between processes executing on the different
computers that are tied together by a network.
● Communication may be implemented via shared memory or
message passing by OS.
5. Error detection
● The OS must be aware of possible errors.
● Errors may be occurring on CPU, memory, I/O devices or user
program.
(Ex. Memory error, power failure, connection failure on network,
lock of paper, arithmetic overflow)
● For each type of error the OS should take an appropriate action to
ensure correct.
6. Resource Allocation.
● When there are multiple users or multiple jobs running at the same
time, resources must be allocated to each of them.
● The OS is must be allocated the resources properly.
7. Accounting
● The OS is to keep track of which users use how much and what kind
of computer resources.
8. Protection
● Protection involves ensuring that all access to system resources is
controlled.
● Security means each user having to authenticate himself or herself
to the system.
14
SYSTEM CALL
[Link] CONTROL
Create, Terminate process.
Load, Execute
End, Abort
get process attributes & set process attributes.
Wait event, Signal event.
Allocate and Free memory.
[Link] MANAGEMENT
Create file, delete file.
Open, close
Read, Write operations.
get file attributes, set file attributes
[Link] MANAGEMENT
Request device, release device.
Read, write, reposition.
Logically attach.
[Link] MAINTENANCE
get time or date, set time or date.
get process file or device attributes.
get system data, set system data.
[Link]
15
SYSTEM PROGRAMS
[Link] MANAGEMENT
create, delete, copy, rename, print, list and generally manipulate files
and directories.
[Link] INFORMATION
[Link] MODIFICATION
Several text editors may be available to create and modify the content
of files stored on disk.
[Link]
16
SYSTEM STRUCTURE
Simple Structure
Layered Structure
SIMPLE STRUCTURE
17
● Provides the file system, CPU scheduling, memory
management, and other operating-system functions.
● More functioning combined into one level, any changes in one
section could affect other areas.
LAYERED APPROACH :
Difficulty:
●Layered approach involves in definition of various layers.
●A layer use only at lower level, so careful planning is necessary.
●Requirement may not be Obvious.
LAYERED APPROACH
18
VIRTUAL MACHINES
The resources of the physical computer are shared to create the virtual
machines
●CPU scheduling can create the appearance that users have their
own processor
●Spooling and a file system can provide virtual card readers and
virtual line printers
●A normal user time-sharing terminal serves as the virtual
●Virtual machine approach involves disk system. So it provides mini
disk in needs of several disk space.
19
IMPLEMENTATION
[Link] Mode :
The virtual machine itself can executes if only user mode.
[Link] Mode :
●Virtual machine s/w can run in monitor mode as its o/s.
●The transfer of user mode to monitor mode can be done easily by:
Running a program or virtual machine in user mode.
Cause transfer to virtual machine mode and it gains the control.
20
● There is no unique solution to the problem of defining the
requirements for an OS.
● Different requirements can result in a variety of solution for
different environments.
(c) IMPLEMENTATION:
Once an operating system is designed, it must be implemented.
Traditionally the OS have been written in assembly language.
Now days, operating system can be written by High Level
Languages.
Some of the operating system written by High Level Languages.
● Master Control Program(MCP) is written by ALGOL.
● MULTICS is written by PL/1.
● Primos is written by FORTRAN.
● UNIX,OS/2,WINDOWS/NT are written by C.
Advantages Using HLL.
●Easy to write program for OS.
●Code can be written faster, easier to understand and debug.
Disadvantages Using HLL.
●Reduced Speed and increased storage space.
●An expert assembly language programmer can produce
efficient small routines for large programs than HLL
programmers.
PROCESS MANAGEMENT
21
PROCESS CONCEPTS:
PROCESS :
PROCESS STATES :
22
Each Process is represented in the operating system by a Process
Control Block (PCB) –also called as task control block.
The PCB contains important information about the specific process
including.
1. Process State :
The state may be new, ready, waiting, running, terminated and so on.
2. Program Counter :
The counter indicates the address of the next instruction to be executed
for this process.
3. Registers :
● The registers vary in number and type depending on the computer
architecture.
● The include accumulator, index register, stack pointers, general
purpose registers and condition code information.
Process
Pointer
State
Process number
Program counter
Registers
Memory limits
List of open files
.
.
.
23
4. CPU Scheduling Information :
This information includes a process priority, pointers to scheduling queues
and any other scheduling parameters.
6. Accounting Information :
This information includes amount of CPU and real-time used, time limits,
account numbers, job or process numbers and so on.
24
THREADS
If the process has multiple threads of control, it can do more than one task
at a time. A single thread of control allows the process to perform only one
task at one time.
●Responsiveness
●Resource Sharing
25
●Economy
●Utilization of multiprocessor architecture
Kernel Threads:
The Kernel performs thread creation, scheduling and management in
kernel space.
It is slower to create and manage than user threads.
MULTITHREADING MODELS :
Many-to-one Model
One-to-One Model
Many-to-Many Model
Many-to-one Model :
● The many-to-one model maps many user-level threads to one kernel
thread.
● Only one thread can access the kernel at a time.
Many-to-One Model
One-to-One Model :
● The one-to-one Model maps each user thread to a kernel thread.
26
● A user thread requires creating the corresponding kernel thread.
One-to-one model
Many-to-Many Model:
● The many-to-many model multiplexes many user-level threads to a
smaller or equal number of kernel threads.
● Developers can create as many user threads as necessary and the
corresponding kernel threads can run in parallel on a multiprocessor.
Many-to-Many Model
PROCESS SCHEDULING :
27
The objective of multiprogramming is to improve the CPU utilization.
(a) Scheduling Queues :
A new process enter the system, they are put into a Job queue which
consists of all processes in the system.
The processes that are residing in main memory and are ready and
waiting to execute are kept on a list called a Ready queue.
There also other queue in the system.
This queue is usually stored in linked list.
The list of processes waiting for a particular I/O device is called a
device queue.
Each device has its own device queue.
(b) Schedulers :
29
(c) Context Switch :
Switching the CPU to another process is called context switching.
It needs to save the state of the old process and loading the state
of the new process.
30
Code For Producer & Consumer Process
while(1) {
while(in == out)
; // do nothing
nextconsumed=buffer[out];
out=(out+1) % BUFFER_SIZE;
/* consume the item in nextconsumed */
}
31
INTERPROCESS COMMUNICATION(IPC)
IMPLEMENTATION QUESTIONS
2. NAMING
Processes that want to communicate must have a way to refer to each
other.
Different combinations of send and receive are possible. When both the
send and receive are blocking, we have a rendezvous between the sender
and the receiver.
4. BUFFERING
● Zero Capacity: The queue has maximum length 0; thus, the link cannot
have any messages waiting in it. In this case, the sender must block
until the recipient receive the messages.
● Bound Capacity: The queue has finite length n; thus, at most n
messages can reside init. If the queue is not full when a new message is
34
sent, the latter is placed in the queue and the sender can continue
execution without waiting.
● Un bounded Capacity: The queue has potentially infinite length ; thus,
any number of messages can wait in it. The sender never blocks.
CPU SCHEDULING
CPU SCHEDULER :
The 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:
[Link] from running to waiting state.
[Link] from running to ready state.
[Link] from waiting to ready.
[Link].
Scheduling under 1 and 4 is non preemptive.
All other scheduling is preemptive.
SCHEDULING CRITERIA :
1. CPU Utilization :
We can keep the CPU as busy as possible.
CPU Utilization may range from 0 to 100%.
2. Throughput :
The number of processes that are completed per time unit is
called throughput.
3. Turnaround time :
The time interval from the time job submission and time of job
completion is called turnaround time.
It includes sum of waiting to get memory, waiting in ready
35
queue, executing on the CPU and doing I/O.
4. Waiting Time :
5. Response Time :
The time from the submission of a request until the first
response is produced is called response time.(ex. Interactive
systems)
SCHEDULING ALGORITHMS :
36
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17 milliseconds
Associate with each process the length of its next CPU burst. Use
these lengths to schedule the process with the shortest time
Two schemes:
●non preemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst
37
Shortest-Remaining-Time-First (SRTF)
SJF is optimal – gives minimum average waiting time for a given set of
processes
If two processes have same length FCFS scheduling is used.
Example:
Consider the following set of process with the length of CPU burst time
3. PRIORITY SCHEDULING
38
Starvation – low priority processes may never execute.
Aging –It increasing the priority of the processes that wait in the
system for long time.
Example :
Gantt chart
0 1 6 16 18 19
[Link] Priority:
It uses measurable quantity. Ex: time limit, memory requirement, CPU
burst etc.
[Link] Priority:
It sets by criteria that are external from operating system. Ex: Important for
process, amount of fund required etc.
0 4 7 10 14 18 22 26 30
5. MULTILEVEL QUEUE
foreground (interactive)
background (batch)
40
Each queue has its own scheduling algorithm
●foreground – RR
●background – FCFS
Scheduling must be done between the queues
●Fixed priority scheduling; (i.e., serve all from foreground then from
background). Possibility of starvation.
●Time slice – each queue gets a certain amount of CPU time which
it can schedule amongst its processes; i.e., 80% to foreground in
RR
●20% to background in FCFS
41
MULTILEVEL FEEDBACK QUEUES
UNIT – II
PROCESS SYNCHRONIZATION
Definition:
42
b) Exit Section
c) Remainder Section
Each process must request permission to enter its critical section. The
section of the code implementing this request is the entry section.
The Critical section may be followed by an exit section.
The remaining code is the remainder section.
do {
entry sections
Critical section
exit section
remainder section
}while(1);
43
decision on which will enter its critical section next, and this selection
cannot be postponed indefinitely.
do {
flag[i]=true;
turn=j;
while(flag[j]&&turn==j);
Critical section
flag[i]=false;
Remainder section
} while(1)
44
● Synchronization Hardware deals with simple hardware instruction.
● Available on so many systems to solve the critical section problem.
Need for Synchronization Hardware
while(true)
{
while(TestAndSet(lock));
critical section
lock=false;
remainder section
}
45
while(TestAndSet(l)==1);
● The unlock operation is implemented as i=0.
The swap instruction operates on the contents of two words, like the test-
and- set instructions, it is executed atomically.
boolean waiting[n];
boolean lock;
do {
key=true;
while(key==true)
swap(lock,key);
critical section
lock=false;
remainder section
}while(1);
46
SEMAPHORES
Synchronization tool that does not require busy waiting.
A Semaphore S is an integer variable
Two standard operations modify S: acquire() and release()
●Originally called P() and V()
Less complicated
Can only be accessed via two indivisible (atomic) operations
acquire( ) {
while S<=0
; //no-op
S--;
}
release( ) {
S++;
}
SEMAPHORE IMPLEMENTATION :
Implementation of acquire() :
acquire( ) {
value--;
if(value<0) {
add this process to list
block ;
}
}
Implementation of release():
release( ) {
value++;
if(value<=0) {
remove a process P from list
wakeup(P);
}
}
P0 P1
[Link](); [Link]();
[Link](); [Link]();
. .
. .
. .
[Link](); [Link]();
48
[Link](); [Link]();
BINARY SEMAPHORES :
These problems are used for testing nearly every newly proposed
synchronization scheme.
49
The structure of the producer process:
Repeat
do
{
………………
Produce an item in next p
………………
wait (empty);
wait (mutex);
………………
add next p to buffer
………………..
signal (mutex);
signal (full);
until false;
50
the content of the shared object whereas others may want to update (ie: to
read and write) the shared object.
If two readers access the shared data object simultaneously no
adverse effects, will result.
If a writer and some other access the shared object simultaneously,
chaos may ensue.
The readers-writers problem has several variations, all involving
priorities.
●The first readers-writers problem, requires that no reader will be
kept waiting unless a writer has already obtained permission to
use the shared object.
●The second readers-writers problem require that once a writer is
ready, that access the object no new readers may start read.
The structure of a writer process:
wait (wrt);
……
writing is performed
……
signal (wrt);
wait (mutex);
readcount++;
if (readcount==1)
wait (wrt);
signal (mutex);
…
reading is performed
…
wait (mutex);
readcount--;
if (readcount ==0)
signal (wrt);
signal (mutex);
52
…
until false;
CRITICAL REGIONS
MOTIVATION :
53
process can access the variable V. The expression B is a Boolean expression.
If the expression is true, statement S is executed. If the two statements,
The critical region construct guards against some simple errors associated
with the semaphore solution to the critical section problem which may be
made by a programmer.
54
region V do S;
the compiler generates the following code:
P(v-mutex);
S;
V(v-mutex);
Critical region may also be nested. In this case, however deadlocks may result.
MONITORS
Syntax of a Monitor
55
Fig: Schematic view of a Monitor
56
Condition Variables :
Condition x, y;
57
Fig: Monitor with Condition Variables
DEADLOCK
58
• Here Process P1 consisting of Resource1 information along with that P1
is waiting to acquire Resource2 information. Here P1 requires additional
resource R2.
• As the same thing P2 process consists of Resource2 Information along
with P2 is waiting to acquire Resource1 (R1) information. Here P2
requires additional resource Resource1.
Hence no one process can continue its processing.
SYSTEM MODEL :
DEADLOCK CHARACTERIZATION
DEADLOCK PREVENTION
Mutual Exclusion – not required for sharable resources; must hold for
non sharable resources.
Hold and Wait – must guarantee that whenever a process requests a
resource, it does not hold any other resources.
●Require process to request and be allocated all its resources before
it begins execution, or allow process to request resources only
when the process has none.
●Low resource utilization; starvation possible.
No Preemption
●If a process that is holding some resources requests another
resource that cannot be immediately allocated to it, then all
resources currently being held are released.
●Preempted resources are added to the list of resources for which
the process is waiting.
●Process will be restarted only when it can regain its old resources,
as well as the new ones that it is requesting.
Circular Wait
● Impose a total ordering of all resource types, and require that
each process requests resources in an increasing order of
enumeration.
60
DEADLOCK AVOIDANCE
available.
● Simplest and most useful model requires that each process declare the
maximum number of resources of each type that it may need.
● The deadlock-avoidance algorithm dynamically examines the resource-
allocation state to ensure that there can never be a circular-wait
condition.
● Resource-allocation state is defined by the number of available and
allocated resources, and the maximum demands of the processes.
Safe-State :
BASIC FACTS :
61
Fig: Safe, Unsafe, Deadlock State
AVOIDANCE ALGORITHMS:
Single instance of a resource type. Use a resource-allocation graph
Multiple instances of a resource type. Use the banker’s algorithm
62
Unsafe State In Resource-Allocation Graph
BANKER’S ALGORITHM:
Multiple instances.
Each process must a priori claim maximum use.
When a process requests a resource it may have to wait.
When a process gets all its resources it must return them in a finite
amount of time.
63
Available: A Vector length m indicates the no. of available resources of
each type.
Vector of length m. If available [j] = k, there
are k instances of resource type Rj available.
Max: Defines the maximum demand of each process.
n x m matrix. If Max [i,j] = k, then process Pi may
request at most k instances of resource type Rj.
Allocation: Defines the no. of resources of each type.
n x m matrix. If Allocation[i,j] = k then Pi is
currently allocated k instances of Rj.
Need: Remaining resources needed for each process.
n x m matrix. If Need[i,j] = k, then Pi may need k
more instances of Rj to complete its task.
SAFETY ALGORITHM:
Finish[i] = true
go to step 2.
[Link] Finish [i] == true for all i, then the system is in a safe state.
64
Request = request vector for process Pi. If Requesti [j] = k then process Pi
wants k instances of resource type Rj.
1. If Requesti Needi go to step 2. Otherwise, raise error condition, since
process has exceeded its maximum claim.
2. If Requesti Available, go to step 3. Otherwise Pi must wait, since
resources are not available.
DEADLOCK DETECTION
Detection algorithm
Recovery scheme
65
2
An algorithm to detect a cycle in a graph requires an order of n
operations, where n is the number of vertices in the graph.
66
DETECTION ALGORITHM :
Finish[i] = true
go to step 2.
[Link] termination.
[Link] preemption.
67
PROCESS TERMINATION:
RESOURCE PREEMPTION :
Rollback – return to some safe state, restart process for that state.
68
●Load time: Must generate relocatable code if memory location is
not known at compile time.
●Execution time: Binding delayed until run time if the process can be
moved during its execution from one memory segment to
another. Need hardware support for address maps (e.g., base
and limit registers).
UNIT – III
MEMORY MANAGEMENT
Memory Definition:
Memory consist of a large array of words or bytes each with its own
address. The CPU fetches instruction from memory using program counter.
ADDRESS BINIDING :
INPUT QUEUE :
69
queue and to load that process into memory. As the process is executed, it
access instruction and data from memory. Eventually when it terminate,
it’s memory space is declared as available.
The above process is done using address binding . A compiler bind the
symbolic address to relocatable address. A Linkage editor (or) Loader
will bind this relocatable address to absolute address.
70
DYNAMIC LOADING AND LINKING
71
System also known as shared libraries.
OVERLAYS
● The size of the process is limited to the size of physical memory , so
that a process can be larger than the amount of memory allocated to it
then overlays technique is used.
● The ideas of overlays is to keep in memory only those instructions and
data that are needed at any given time. And the other instructions
needed are loaded into space that was occupied by previous
instructions no larger needed.
Ex:
Consider two process assembles the size of the components are as
follows;
Process-1 70kb
Process-2 80kb
Symbol table 20kb
Common routine 30kb
To load everything we need 200kb of memory. If only 150kb is available,
we can’t run our process. As process-1 and process-2 needn’t be at the same
thing in memory .
Thus two overlays are defined:
Symbol
table
Common
routines
72
Overlays
drivers
RUNTIME MAPPING :
73
SWAPPING
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped.
74
CONTIGUOUS ALLOCATION
[Link]-partition allocation:
75
● Hole – block of available memory; holes of various size are scattered
throughout memory
● When a process arrives, it is allocated memory from a hole large
enough to accommodate it
● Operating system maintains information about:
NON-CONTIGUOUS ALLOCATION
SEGMENTATION:
Memory-management scheme that supports user view of memory
A program is a collection of segments. A segment is a logical unit such
as:
* main program,
* procedure,
* function,
* method,
77
* object,
* local variables, global variables,
* common block,
* stack,
* symbol table, arrays
The logical address space is the collection of segments. Each segment
has a name and length. The logical address consists of two types.
Hardware:
In segmentation the mapping is effected by segment table. Each entry of
segment has segment base and segment limit.
Segment base:
Starting physical address where the segment reside in memory.
Segment limit:
Length of the segment.
The segment number is used as index into segment table. The off set d
of logical address must be between o and the segment limit if it is not,
we trap the OS, if it is legal then it is added to produce the address in
physical memory of desired byte.
Segmentation Hardware
78
Example:
The segment 0 to 4 is stored as follows in memory. For example segment
2 is 400 bytes long and begins at 4300 then the physical memory address is
the reference byte 53 of segment 2 is mapped as
4300+53=4353.
Example of Segmentation
editor
Segment 0
0
1
Physical memory
editor
Segment 0
limit Base
25286 43062
8850 Segment
90003 1
Data 1
0
1
Paging Hardware
82
Paging example for a 32-byte memory with 4-byte pages
Using a page size of a 4 bytes and physical memory of 32 bytes (8
bytes) we shown an example of how the user view of memory can be mapped
into physical memory. Logical address 0 is page 0 offset 0. Indexing into the
page table, we find a page 0 is in frame 5.
The first page of the process is loaded into one of the allocated
process frames and the frame no; is put in to the page table for these process.
The next page is loaded into the another frames and its frame no; is put in to
the page table and so on.
83
FREE FRAMES :
HARDWARE SUPPORT :
The hardware implementation of the page table can be done in a no.
of different ways.
The problem with this approach is the time required to access a user
memory location. If we want to access location I, we first index into the page
table , using the value in the PTBR offset by the page no. for i. this task
required a memory address access. It provides us with the frame no., which is
combined with the page offset to produce the actual address we can then
access the desired place in memory, with this scheme two memory access
are needed to access a byte(one for the page table, one for the byte).
ASSOCIATIVE MEMORY :
page# frame#
Associative register are used with pages tables in the following way.
The associative registers contain only a few of the page-table entries. When a
logical address is generated by the CPU its page number is presented to a set
of associative registers that contain page no and their corresponding frame
number. If the page no is found in the associative register its frame number is
immediately available and is used to access memory.
85
PROTECTION :
At the same time that the physical address is being computed the
protection bits can be checked to verify that no writes are being made to a
read-only page. An attempt to write to a read-only page causes a hardware
trap to the operating system (memory protection violation)
86
One more bit is generally attached to each entry in the page table; a valid-
invalid bit. When this bit is set to “valid” this value indicates that the associated
page is in the logical address space and it thus the page is not in the
processes logical address space.
Hierarchical Paging
Hashed Page Tables
Inverted Page Tables
87
Break up the logical address space into multiple page tables
A simple technique is a two-level page table
A logical address (on 32-bit machine with 1K page size) is divided into:
● a page number consisting of 22 bits
● a page offset consisting of 10 bits
Since the page table is paged, the page number is further divided into:
● a 12-bit page number
● a 10-bit page offset
Thus, a logical address is as follows:
88
page number page offset
P1 P2 d
where pi is an index into the outer page table, and p2 is the displacement
within the page of the outer page table
Address-Translation Scheme
89
HASHED PAGE TABLES :
<process-id,page-number,offset>
SHARED PAGES :
91
Shared code
●One copy of read-only (reentrant) code shared among processes
(i.e., text editors, compilers, window systems).
●Shared code must appear in same location in the logical address
space of all processes.
Private code and data
●Each process keeps a separate copy of the code and data.
●The pages for the private code and data can appear anywhere in
the logical address space.
Re-entrant code (also called pure code) is non self-modifying code. If the
code is re-entrant, then is never changes during execution. Thus two or more
processes can execute the same code at the same time. Each process has its
own copy of register and data storage to hold the data for the process
execution.
UNIT – IV
VIRTUAL MEMORY
92
Virtual memory is a technique that allows the execution of processes
that may not be completely in memory. The main visible advantage of this
scheme is that programs can be larger than physical memory.
Virtual memory is the separation of user logical memory from physical
memory. This separation allows an extremely large virtual memory is
available.
DEMAND PAGING :
Demand Paging
93
With this scheme we need some form of hardware support to
distinguish between those pages table, that are in memory and those pages
that are in the disk.
The valid – invalid bit scheme can be used for this purpose. This time,
how ever, when this bit is set to “valid”, this valid indicate that the associated
page is both legal and in memory. If the bit is set to “invalid” this valued
indicates that the page either is not valid or is valid but is currently on the disk.
PAGE TABLE :
This page table has the ability to make an entry invalid through a valid –
invalid bit or special value of protection bits.
Page Table
94
[Link] check an internal table (usually kept with the process control block) for
this, process to determine whether the reference was a valid or invalid
memory access.
2. If the reference was invalid, we terminate the process. If it was valid, but we
have not get brought in that page, we know page in the letter.
3. We find a free frame (by taking one from the free frame list).
4. We schedule a disk operation to read the decide operation page in to the
newly allocated frame.
5. When the disk read is complete, we modified the internal table kept with in
the process and the page table to indicate the page is now in memory.
[Link] restart the instruction that was interrupted by the illegal address track.
The process can now access the page as through it had always been in
memory.
Secondary memory:
This memory holds those pages that are not present in main memory.
The secondary memory is usually a high speed disk. It is known as the swap
device, and the section of disk used for this purpose is known as swap space
or backing store.
Page Fault
95
PAGE REPLACEMENT :
96
BASIC SCHEME :
If no frame is free we find one that is no currently being used and free it.
We can free a frame by writing its content to swap space and changing the
page table to indicate that the page is no longer in memory. The free frame
can now be used to hold the page for which the process faulted.
The page replacement involves the following steps:
97
3. Read the desired page into the free frame change the page and
frame table.
4. restart the user process
Page Replacement
1. FIFO Algorithm:
It is simplest replacement algorithms
A FIFO algorithm associate with each page time when that page was
brought into memory.
A pages replaced by choosing a old page
98
FIFO queue is created to hold all pages
FIFO Page Replacement
Optimal algorithm:
An optimal page replacement algorithm has the lowest page fault. Rate of
all algorithms. Use of this page replacement algorithm it the lowest possible
page fault rate for a fixed no of frames.
Here the page 7 is replaced because it is used only after the reference
18, whereas page 0 is used at 5 and page 1 is used at 14.
LRU ALGORITHM:
Least recently used algorithm, here we replace the page that has not been
used for the long period of time. It associates with each page of that pages
last use.
99
LRU Page Replacement
100
ENHANCED ALGORITHM:
101
COUNTING ALGORITHM:
[Link] algorithm:
Least frequently used page replacement algorithm.
The page with smallest count will be replaced.
Used page have larger count and the page no. larger used has small
count.
[Link] algorithm:
Most frequently used page replacement algorithm.
Based on the pages with smallest count was probably just brought in &
has get to be used.
PAGE BUFFERING ALGORITHM:
THRASHING:
If the process does not have the number of frame it needs to support
pages in active use, it will quickly page fault.
At this point, it must replace some pages. However since all its pages are
102
in active use, it must replace a page that will be needed again. It quickly fault
again & again replacing pages.
This high paging activity is called thrashing. Thrashing results in severe
performance problem. Operating system monitors CPU utilization. If CPU
utilization is low, we increase the degree of multiprogramming by introducing a
new process to the system.
A global page replacement algorithm is used, to replace pages without
regard to the process, to which they begin.
Now suppose that a process enters a new face in its execution and
needs more frames it started fault takes the frames away from other
processes.
This process needs those pages, so they also fault. These faulting
processes must be use paging device to swap pages in and out.
Cpu scheduler monitors the decreasing cpu utilization and increasing
degree of multi-programming as a result.
FILE SYSTEM
FILE CONCEPT
Text File:
Is a sequence of characters organized into lines.
Source File:
Sequence of subroutines and functions.
Executable File:
Is a series of code section that the loader can bring the into memory and
execute.
File Types:
If an operating system recognizes the type of a file it can operate on the
file in reasonable ways.
A common technique for implementing file types is to include as part of
the file name.
The name is split into two parts.
104
1. Name
2. Extension
Name:
Specifies the name of the file.
Extension:
105
File Structure:
File types may also be used to indicate the internal structure of the file.
ACCESS METHODS
File store information when I t is used, this information must be access and
106
read into computer memory. There are several ways to access the
information.
Sequential Access:
Simplest access method. Information processed in order, one record
after the other. The operation on the file are read and write. It is based on tape
model of a file.
107
Other Access Method:
This is additional method, generally involve the construction of index
for the file.
The index like an index in the back of book contains pointers to the
carious blocks.
To find an entry in the file
1. First search the index.
2. Use ptr to access the file directly.
3. Find the desired entry.
DIRECTORY STRUCTURE
108
Directory structure provides the information about file system and
organizes and manages the system. The organization is done in two parts.
Operation On Directory:
109
backup copy in case of system failure. There are various types of directory
structures.
1. Single level directory:
Simplest directory structure.
All files are contained in same directory.
It has significant limitations.
The files must have unique names.
As the number of file increases, if is difficult to remember the
names of all files.
Single - level Directory
110
3. Tree structured directories:
Tree is a most common directory. The tree has a two root
directory.
Each file in the system has unique path name.
A path name is the path from the root through all the
subdirectories.
Path name can be of two types:
1. Absolute path name.
2. Relative path name.
Absolute path name- begins at the root and follows a path down to the
specified files, giving the directory name on the path. Ex: root/spoll/mail/prt/
first.
Relative path name- it is defined as the path name from the current
directory.
111
4. Acyclic graph structure:
It allows directories to have shared sub direct files.
It is flexible then simple tree.
Also it is complex because is has mare absolute path.
No cycles are ensured.
The deletion is done using reference list where list is empty the
file is deleted.
112
[Link] graph directory:
Cycles are allowed in the directory structures.
When new links are added to tree structure the tree structure is
destroyed resulting in a simple graph structure. While searching a
file second search can be avoided.
PROTECTION
Type Of Access:
113
Read – read from the file.
Write – write or rewrite the file.
Execute – load the file into memory or execution.
Append – write new information at the
Delete – delete the file and free its space possible revise.
List – list the name and attributes of the files.
Other operations such as renaming copying, editing can also are controlled.
Access List And Groups:
The most common approach to the protection problem is to make
access dependent on the identity if the user. The most general scheme to
implement identify dependent access is to associate with each file and
directory.
Access List:
Specifies user name and type of access allowed for each user.
The main problem is due to length of access list.
These problems can be resolved by use of condensed version of
access list/
Length of access list can be condensed by the classification of user as
given below:
●Owner – the user who create the file.
●Group – a set of user who sharing the file and need similar access
in a group.
●Universe – all the users in the system belongs to universe.
Other Protection Approaches:
114
Access to computer system controlled by password.
Access to each file controlled by a password
CONSISTENCY SEMANTICS
This is an important criteria for evolution of any file that supports sharing
of files. It is always enclosed between open and close operations.
UNIX Semantics:
Unix file system uses the following:
Rights to open a file by a user or visible immediately to others.
There is mode of sharing.
SESSION Semantics:
File system structure disk provides the bulk of secondary storage on which
a file system is maintained.
115
Disks are performed in a unit of blocks.
Each block is divided into one or more sectors.
Disks have two important characteristics
1. They can be re-written.
2. It can be accessed sequentially or randomly.
File system generally composed of different levels. Each level in the design
uses the features of lower to create new feature for use by higher level.
I/O Control:
116
The lowest level.
Its consist of device drivers and interrupt handlers to transfer
information between the memory and the disk system.
Basic File System:
ALLOCATION METHOD
Contiguous Allocation:
117
Contiguous allocation of disk space
Linked Allocation:
118
Indexed Allocation:
The pointers are brought together into a block called index block.
Each file has own index block.
Supports direct access.
It does not suffer from external fragmentation but suffer from wasted
space to store index block.
119
FREE SPACE MANAGEMENT
Keeps track of free disk space, the system maintain a free space list.
It records all disk blocks that are not allocated.
Search for free space list for the required amount of space.
And allocated the space to the new file.
The disk space is then removed from free space list.
When the file is deleted, then it is added to free space list.
[Link] Vector:
120
The free space list is implemented as a bit vector or bit map.
Bit free block is represented by bit one.
Allocated block is a reference by bit zero.
Ex:
consider the following disk blocks,2,3,4,5,8,9,10,11,12,13,17,18,25,26&27
are free and the rest of the block are allocated. Then the bit vector would be
00001100011111111111000000000111………
Advantage:
It is effective to find free space list.
[Link] List:
Another approach is to link together all the free disk blocks, keeping a
pointer to the first free block is special location in the disk & catching it in
memory. The first block contains a pointer to the next free disk block &
so on.
[Link]:
121
[Link]:
UNIT - 5
I/O SYSTEMS
The two main jobs of a computer are I/O and processing. The main job is I/
O and the processing is merely incidental. We browse a web page or edit a file,
our immediate interest is to read or enter some information, not to compute
an answer.
The role of the operating system in computer I/O is to manage and control
I/O operations and I/O devices.
I/O devices vary so widely in their function and speed (mouse, hard disk
and CD-ROM), a variety of methods are needed to control them.
I/O HARDWARE
122
A device communicates with a computer system by sending signals
over a cable or even through the air. The device communicates with the
machine via a connection point(or port).
123
Polling
Determines state of device
ocommand-ready
obusy
oError
Busy-wait cycle to wait for I/O from device
Interrupts
CPU Interrupt-request line triggered by I/O device
Interrupt handler receives interrupts
Maskable to ignore or delay some interrupts
Interrupt vector to dispatch interrupt to correct handler
oBased on priority
oSome nonmaskable
Interrupt mechanism also used for exceptions
124
Intel Pentium Processor Event-Vector Table
125
Direct Memory Access
126
APPLICATION I/O INTERFACE
Application can open a file on a disk without knowing what kind of disk
it is, and how new disks and other devices can be added to a computer
without the operating system being disrupted.
Making the I/O subsystem independent of the hardware simplifies the
job of the operating system developer.
127
A kernel I/O structure
128
●Read-write, read only, or write only : Some devices perform both
input and output, but others support only one data direction.
NETWORK DEVICES :
The performance and addressing characteristics of network I/O differ
significantly from those of disk I/O, most operating system provide a
network I/O interface that is different from the read( ),write( ) and seek( )
interface used for disks.
129
To support the implementation of servers, the sockets interface also
provides a function called select( ) that manages a set of sockets.
131
●Always just a copy
●Key to performance
Error Handling
OS can recover from disk read, device unavailable, transient write
failures
Most return an error number or code when I/O request fails
System error logs hold problem reports.
I/O Protection
Kernel keeps state info for I/O components, including open file
tables, network connections, character device state
Many, many complex data structures to track buffers, memory
allocation, “dirty” blocks
Some use object-oriented methods and message passing to
implement I/O
132
UNIX I/O Kernel Structure
133
controller by writing into the device control registers.
The device controller operates the device hardware to perform the data
transfer.
The driver may poll fro status and data or it may have set up a DMA
transfer into kernel memory. The transfer is managed by a DMA
controller, which generates an interrupt when the transfer completes.
The correct interrupt handler receives the interrupt via the interrupt-
vector table, stores any necessary data, signals the device driver and
returns from the interrupt.
134
The device driver receives the signal, determines which I/O request
completed, determines the request’s status and signals the kernel I/O
subsystem that the request has been completed.
The kernel transfers data or return codes to the address space of the
requesting process and moves the process from the wait queue back to
the ready queue.
Moving the process to the ready queue unblocks the process. When
the scheduler assigns the process to the CPU, the process resumes
execution at the completion of the system call.
135
PERFORMANCE
Intercomputer Communications
Improving Performance
Reduce number of context switches
Reduce data copying
Reduce interrupts by using large transfers, smart controllers, polling
Use DMA
Balance CPU, memory, bus, and I/O performance for highest
throughput
136
Device-Functionality Progression
PROTECTION
137
GOALS OF PROTECTION
DOMAIN OF PROTECTION
Each object has a unique name that differentiates it from all other
objects in the system, and each can be accessed only through well-
defined and meaningful operation.
CPU – Execute.
Memory segments - Read and write.
CD-ROM - Read.
Tape drives - read, written, and rewound.
Data files - created, opened, read, written, closed and deleted.
138
program files - read, written, executed and deleted.
DOMAIN STRUCTURE :
Each domain defines a set of objects and the types of operations that
may be invoked on each object.
Each user may be a domain. Domain switching occurs when the user is
changed generally when one user logs out and another user logs in.
139
temporarily.
When the setuid bit is on, the user-id is set to that of the owner of the
file B. When the process exits, this temporary user-id change ends.
ACCESS MATRIX
140
Our model of protection can be viewed abstractly as a matrix called an
access matrix.
The rows of the access matrix represent domains and the column
represent objects.
The entry access(i,j) defines the set of operations that a process,
executing in domain Di, can invoke on object Oj.
There are four domains and four objects, three files(F1,F2,F3) and one laser
printer.
When a process executes in domain D1 it can read files F1 and F3. A process
executing in domain D4 has the same privileges as it does in domain D1
but in addition, it can also write onto files F1 and F3.
The laser printer can be accessed only by a process executing in domain
D2.
Access Matrix
141
Access matrix with domain as objects
● Copy
● Owner
● Control
The ability to copy an access right from one domain (row) of the access
matrix to another is denoted by an asterisk(*) appended to the access right.
142
Access matrix with copy rights
The owner right controls these operations. If access(i,j) includes the owner
right, then a process executing in domain Di can add and remove any right
in any entry in column j.
Domain D2 is the owner of F2 and F3, and thus can add and remove any
valid right within these two columns.
143
Access Matrix With Owner Rights
144
THE SECURITY PROBLEM
The operating system can provide (with appropriate aid from the
hardware) that allow user to protect their resources(usually program &
data).
Security violations (or misuse) of the system can be categorized as
intentional (malicious) or accidental. It is easier to protect against
accidental misuse than against malicious misuse.
Malicious access are the following:
● Unauthorized reading of data (or theft of information).
● Unauthorized modification of data.
● Unauthorized destruction of data.
● Preventing legitimate use of the system (or denial of service).
145
To protect the system, we must take security measures at four levels:
1. Physical: The site or sites containing the computer systems must be
physically secured against armed or surreptitious entry by intruders.
2. Human: Users must be screened carefully to reduce the chance of
authorizing a user who then gives access to an intruder (in exchange for
a bribe, for example).
3. Network: Much computer data in modern systems travels over private
leased lines, shared lines like the internet, of dial-up lines. The
interception of this data could be just as harmful as the break-in of a
computer. The interruption of these communications could be a remote
denial-of-service attack and diminish user’s use of and trust of the
system.
4. Operating system: The system must protect itself from accidental or
purposeful security breaches.
AUTHENTICATION
Centralized Environment :
Distributed Environment :
146
A message passing through the network can be tapped at multiple
locations in distributed systems.
USER AUTHENTICATION
PASSWORD :
PASSWORD VULNERABILITIES :
147
Some systems force the user to select hard-to-remember or long
passwords.
Less security than systems that allow easy passwords.
Some systems also age passwords, forcing users to change their
passwords at regular intervals(every 3 months).
ENCRYPTED PASSWORDS :
The UNIX system uses encryption to avoid the necessity of keeping its
password list secret.
Given a function value f(x), however it is impossible to compute x. This
function is used to encode all passwords. Only encoded passwords are
stored.
When a user presents a password, it is encoded and compared against
the stored encoded password.
For eg, The phrase “My mother’s name is katherine”, the password is
“Mmnisk”.
BIOMETRICS :
ADDITIONAL PASSWORDS :
CONTINUOS CHALLENGE :
PROGRAM THREATS
When a program written by one user may be used by another user, misuse
and unexpected behavior may ensue.
Trojan Horse :
149
Trap Door :
The code might check for a specific user ID or password and it might
circumvent normal security procedures.
A clever trap door could be included in a compiler.
The compiler could generate standard object code as well as a trap
door, regardless of the source code being compiled.
Trap door pose a difficult problem because to detect them, we have to
analyze all the source code for all components of a system.
WORMS :
Internet Worms :
151
Cryptography as a Security Tool
Cryptography enables a recipient of a message to verify that the
message was created by some computer possessing a certain key –
the key is the source of the message.
A sender can encode its message so that only a computer with a
certain key can decode the message so that the key becomes the
destination.
VIRUSES :
viruses are designed to spread into other programs and can wreak
havoc in a system, including modifying of destroying files and causing
system crashes and program malfunctions.
In recent years, a common form of virus transmission has been via the
exchange of Microsoft Office files, such as Microsoft Word documents.
152
Purchasing unopened software from vendors and avoiding free or
pirated copies from public sources or disk exchange is the safest route
to preventing infection.
Even new copies of legitimate software applications are not immune to
virus infection.
To avoid opening any email attachments from unknown users.
Denial of Service :
ENCRYPTION
SYMMETRIC ENCRYPTION :
155
Blocking I/O operations suspend the execution of an application until the I/O operation completes, potentially causing delays if the resource is busy. Non-blocking I/O allows an application to continue execution while waiting for I/O completion, thus improving responsiveness, especially in interactive applications like GUIs. However, non-blocking I/O can require more complex programming to manage asynchronous events and handle partial data transfers .
The command-interpreter system acts as an interface between the user and the operating system, allowing the execution of commands and management of processes. Its implementation varies; some systems, like UNIX, include it as a separate program, often referred to as a shell, whereas others, such as some versions of MS-DOS, incorporate it directly into the kernel. This integration impacts how commands are processed and executed, affecting performance and flexibility .
The protection system in an operating system enhances reliability and security by controlling access to system resources, ensuring that only authorized entities can perform specific operations. It enables error detection at interfaces between system components, thus preventing potential malfunctions from propagating. By implementing access control policies and enforcing permissions, protection systems guard against unauthorized access and ensure that user actions do not disrupt system stability .
Hierarchical page tables break the logical address space into multiple levels of page tables, reducing the size of individual page tables and optimizing address translation for large address spaces. In a two-level page table system, the logical address is split into a primary and secondary page number, directing access through multiple page table levels to find the correct physical address. This method reduces memory usage for page tables compared to single-level tables but adds complexity to address translation operations .
Translation Look-aside Buffers (TLBs) enhance paging system efficiency by caching a significant portion of the page-table entries, thereby speeding up address translation. Upon a virtual address generation, TLBs quickly return the frame number if the page is cached, avoiding slower main memory accesses to the page table. However, TLBs are limited in size, and frequent context switching may lead to reduced effectiveness due to TLB flushes and cache misses, potentially incurring performance penalties .
Operating systems utilize mechanisms such as protection bits and validation checks within the page table, preventing unauthorized access to memory. Protection bits define the read/write capabilities of pages, while validation bits (valid/invalid bits) ensure accurate logical versus physical memory mapping. Unauthorized access attempts trigger hardware traps, enabling the OS to enforce protection parameters and prevent processes from accessing unauthorized memory regions .
System calls in operating systems facilitate process communication through methods such as message passing and shared memory. Message passing allows isolated exchanges of data between processes, suitable for distributed systems and maintaining process isolation. Shared memory offers faster communication as processes can directly read and write to a common memory space, beneficial for high-speed interactions. However, it requires careful synchronization to avoid data inconsistencies .
A layered system structure divides an operating system into distinct levels, each building upon the functions of lower layers, promoting modularity and simplifying debugging and system updates. This contrasts with a monolithic design like MS-DOS, where functionality is integrated tightly without clear separation, complicating maintenance and scalability. While layering offers improved reliability and maintainability, it can introduce performance overhead due to additional layers of abstraction in operation execution .
Network interconnectivity profoundly influences operating system design, demanding robust message routing protocols to ensure reliable data transfers across potentially vast and heterogeneous networks. Operating systems must implement efficient routing strategies and maintain connection integrity, factoring in latency and potential data loss. Security considerations add complexity by necessitating encryption and authentication practices to protect data integrity and user privacy. These requirements impact OS resource allocation and drive the need for adaptable and secure networking modules .
Paging mitigates memory fragmentation by dividing memory into fixed-size blocks known as frames and corresponding blocks within processes called pages. This allows non-contiguous allocation of process pages in physical memory, minimizing external fragmentation. However, it introduces internal fragmentation since the last page of a process may not completely fill a frame. Additionally, paging requires a page table for address translation, which can increase memory access time and overhead due to the management of these tables and their entries .