(R18A0504) Operating Systems
(R18A0504) Operating Systems
ON
OPERATING SYSTEMS
B.TECH
II YEAR - I SEM
(2020-21)
L T/P/D C
II Year B.Tech IT-ISem 3 -/-/- 3
Objectives:
Students will be able:
To learn the mechanisms of OS to handle processes and threads and theircommunication
To learn the mechanisms involved in memory management in contemporaryOS
To gain knowledge on distributed operating system concepts that includes architecture,
Mutual exclusion algorithms, deadlock detection algorithms and agreementprotocols
To know the components and management aspects of concurrencymanagement
UNIT ‐ I:
Introduction: Concept of Operating Systems, Generations of Operating systems, Types of Operating
Systems, OS Services, System Calls, Structure of an OS - Layered, Monolithic, Microkernel Operating
Systems, Concept of Virtual Machine. Case study on UNIX and WINDOWS Operating System.
UNIT ‐ II:
Processes: Definition, Process Relationship, Different states of a Process, Process State transitions,
Process Control Block (PCB), Context switching
Thread: Definition, Various states, Benefits of threads, Types of threads, Concept of multithreads
Process Scheduling: Foundation and Scheduling objectives, Types of Schedulers, Scheduling criteria:
CPU utilization, Throughput, Turnaround Time, Waiting Time, Response Time. Scheduling algorithms:
Pre-emptive and Non pre-emptive, FCFS, SJF, RR. Multi processor scheduling: Real Time scheduling:
RM and EDF.
UNIT ‐ III:
Inter-process Communication: Critical Section, Race Conditions, Mutual Exclusion, Hardware Solution,
Strict Alternation, Peterson’s Solution, The Producer\Consumer Problem, Semaphores, Event
Counters, Monitors, Message Passing, Classical IPC Problems: Reader’s & Writer Problem, Dinning
Philosopher Problem etc.
Deadlocks: Definition, Necessary and sufficient conditions for Deadlock, Deadlock Prevention,
Deadlock Avoidance: Banker’s algorithm, Deadlock detection and Recovery.
UNIT ‐ IV:
Memory Management: Basic concept, Logical and Physical address map, Memory allocation:
Contiguous Memory allocation – Fixed and variable partition–Internal and External fragmentation and
Compaction; Paging: Principle of operation – Page allocation – Hardware support for paging,
Protection and sharing, Disadvantages of paging.
Virtual Memory: Basics of Virtual Memory – Hardware and control structures – Locality of reference,
Page fault , Working Set , Dirty page/Dirty bit – Demand paging, Page Replacement algorithms:
Optimal, First in First Out (FIFO), Second Chance (SC), Not recently used (NRU) and Least Recently
used (LRU).
UNIT ‐ V:
I/O Hardware: I/O devices, Device controllers, Direct memory access Principles of I/O Software: Goals
of Interrupt handlers, Device drivers, Device independent I/O software, Secondary-Storage Structure:
Disk structure, Disk scheduling algorithms
File Management: Concept of File, Access methods, File types, File operation, Directory structure, File
System structure, Allocation methods (contiguous, linked, indexed), Free-space management (bit
vector, linked list, grouping), directory implementation (linear list, hash table), efficiency and
performance.
Disk Management: Disk structure, Disk scheduling - FCFS, SSTF, SCAN, C-SCAN, Disk reliability, Disk
formatting, Boot-block, Bad blocks
TEXT BOOKS:
1. Operating System Concepts Essentials, 9th Edition by AviSilberschatz, Peter Galvin, Greg
Gagne, Wiley Asia StudentEdition.
2. Operating Systems: Internals and Design Principles, 5th Edition, William Stallings, Prentice Hall
of India.
REFERENCE BOOKS:
1. Operating System: A Design-oriented Approach, 1st Edition by Charles Crowley, Irwin
Publishing
2. Operating Systems: A Modern Perspective, 2nd Edition by Gary J. Nutt,Addison-Wesley
3. Design of the Unix Operating Systems, 8th Edition by Maurice Bach, Prentice-Hall ofIndia
4. Understanding the Linux Kernel, 3rd Edition, Daniel P. Bovet, Marco Cesati, O'Reilly and
Associates
Course Outcomes :
At the end of the course students will be able to:
1. Create processes andthreads.
2. Develop algorithms for process scheduling for a given specification of CPU utilization,
Throughput, Turnaround Time, Waiting Time, ResponseTime.
3. For a given specification of memory organization develop the techniques for optimally allocating
memory to processes by increasing memory utilization and for improving the accesstime.
4. Design and implement file managementsystem.
5. Develop the I/O management functions in OS for the given I/O devices andOS.
MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF INFORMATION TECHNOLOGY
INDEX
S. No Topic Page no
Unit
Each computer system includes a basic set of programs called the operating system. The most
important program in the set is called the kernel. It is loaded into RAM when the system boots
and contains many critical procedures that are needed for the system to operate. The other
programs are less crucial utilities; they can provide a wide variety of interactive experiences for
the user—as well as doing all the jobs the user bought the computer for—but the essential
shape and capabilities of the system are determined by the kernel. The kernel provides key
facilities to everything else on the system and determines many of the characteristics of higher
software. Hence, we often use the term "operating system" as a synonym for "kernel."
o Interact with the hardware components, servicing all low-level programmable elements
included in the hardwareplatform.
o Provide an execution environment to the applications that run on the computer system
(the so-called user programs).Some operating systems allow all user programs to directly play
with the hardware components (a typical example is MS-DOS ). In contrast, a Unix-like
operating system hides all low-level details concerning the physical organization of the
computer from applications run by the user. When a program wants to use a hardware
resource,itmustissuearequesttothe operatingsystem.Thekernelevaluatestherequest and, if it
chooses to grant the resource, interacts with the proper hardware components on behalf of the
user program.To enforce this mechanism, modern operating systems rely on the availability of
specific hardware features that forbid user programs to directly interact with low-level
hardware components or to access arbitrary memory locations. In particular, the hardware
introduces at least two different execution modes for the CPU: a nonprivileged mode for user
programs and a privileged mode for the kernel. Unix calls these User Mode and Kernel Mode ,
respectively.In the rest of this chapter, we introduce the basic concepts that havemotivated
An Operating System supplies different kinds of services to both the users and to the programs
as well. It also provides application programs (that run within an Operating system) an
environment to execute it freely. It provides users the services run various programs in a
convenient manner.
User Interface
ProgramExecution
File systemmanipulation
Input / Output Operations
Communication
ResourceAllocation
ErrorDetection
Accounting
This chapter will give a brief description of what services an operating system usually provide to
users and those programs that are and will be running within it.
SYSTEM CALLS
System calls provide an interface to the services made available by an operating system.
These calls are generally available as routines written in C and C++, although certain low-
level tasks (for example, tasks where hardware must be accessed directly) may have to
be written using assembly-language instructions.
File Management :System calls that need to be able to create() and delete() files. Either
system call requires the name of the file and perhaps some of the file’s attributes. Once
the file is created, we need to open() it and to use it. We may also read(), write(), or
reposition() (rewind or skip to the end of the file, for example). Finally, we need to close()
the file, indicating that we are no longer using it.
Device Management: A system with multiple users may require us to first request() a
device, to ensure exclusive use of it. After we are finished with the device, we release() it.
These functions are similar to the open() and close() system calls for files. Once the
device has been requested (and allocated to us), we canread(),
write(), and (possibly) reposition() the device, just as we can with files.
Information Maintenance: Many system calls exist simply for the purpose of transferring
information between the user program and the operating system. time() and date().
dump() - This provision is useful for debugging. A program trace lists each system call as
it isexecuted.
Modules: operating-system design involves using loadable kernel modules. Here, the
kernel has a set of core components and links in additional services via modules, either
at boot time or during run time. This type of design is common in modern
implementations of UNIX, such as Solaris, Linux, and Mac OS X, as well asWindows
Hybrid Systems: In practice, very few operating systems adopt a single, strictly defined
structure. Instead, they combine different structures, resulting in hybrid systems that
address performance, security, and usability issues. For example, both Linux and Solaris
are monolithic, because having the operating system in a single address space provides
very efficient performance. However, they are also modular, so that new functionality
can be dynamically added to thekernel.
Mac OS X : The Apple Mac OS X operating system uses a hybrid structure. It hass a layered
system.
iOS: iOS is a mobile operating system designed by Apple to run its smartphone, the
Android: The Android operating system was designed by the Open Handset Alliance (led
primarily by Google) and was developed for Android smartphones and tablet computers.
UNIT ‐ II:
Processes: Definition, Process Relationship, Different states of a Process, Process State
transitions, Process Control Block (PCB), Context switching
Thread: Definition, Various states, Benefits of threads, Types of threads, Concept of
multithreads Process Scheduling: Foundation and Scheduling objectives, Types of Schedulers,
Process
A process is basically a program in execution. The execution of a process must progress in a
sequential fashion.
A process is defined as an entity which represents the basic unit of work to be implemented in
the system.
To put it in simple terms, we write our computer programs in a text file and when we execute
this program, it becomes a process which performs all the tasks mentioned in the program.
When a program is loaded into the memory and it becomes a process, it can be divided into
four sections ─ stack, heap, text and data. The following image shows a simplified layout of a
process inside main memory
Stack
The process Stack contains the temporary data such as method/function parameters, return
address and local variables.
Heap
Text
This includes the current activity represented by the value of Program Counter and the
contents of the processor's registers.
Data
Program
A program is a piece of code which may be a single line or millions of lines. A computer
program is usually written by a computer programmer in a programming language. For
example, here is a simple program written in C programming language –
int main() {
return 0;
A computer program is a collection of instructions that performs a specific task when executed
by a computer. When we compare a program with a process, we can conclude that a process is
a dynamic instance of a computer program.
is known as an algorithm. A collection of computer programs, libraries and related data are
referred to as a software.
In general, a process can have one of the following five states at a time.
1 Start
2 Ready
4 Waiting
5 Terminated or Exit
1 Process State
2 Process privileges
3 Process ID
4 Pointer
5 Program Counter
6 CPU registers
9 Accounting information
This includes the amount of CPU used for process execution, time
limits, execution ID etc.
10 IO status information
The architecture of a PCB is completely dependent on Operating System and may contain
different information in different operating systems. Here is a simplified diagram of a PCB
The Operating System maintains the following important process scheduling queues −
Ready queue − This queue keeps a set of all processes residing in main memory, ready
and waiting to execute. A new process is always put in thisqueue.
Device queues − The processes which are blocked due to unavailability of an I/O device
constitute thisqueue.
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority,
etc.). The OS scheduler determines how to move processes between the ready and run
queues which can only have one entry per processor core on the system; in the above
diagram, it has been merged with theCPU.
Two-State ProcessModel
Two-state process model refers to running and non-running states which are described
below
1 Running
2 Not Running
Processes that are not running are kept in queue, waiting for their
turn to execute. Each entry in the queue is a pointer to a
particular process. Queue is implemented by using linked list. Use
of dispatcher is as follows. When a process is interrupted, that
process is transferred in the waiting queue. If the process has
completed or aborted, the process is discarded. In either case,
the dispatcher then selects a process from the queue toexecute.
Schedulers
Schedulers are special system software which handle process scheduling in various ways. Their
main task is to select the jobs to be submitted into the system and to decide which process to
run. Schedulers are of three types −
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
Long Term Scheduler
It is also called a job scheduler. A long-term scheduler determines which programs are
admitted to the system for processing. It selects processes from the queue and loads them
into memory for execution. Process loads into the memory for CPUscheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O
bound and processor bound. It also controls the degree of multiprogramming. If the degree of
multiprogramming is stable, then the average rate of process creation must be equal to the
average departure rate of processes leaving the system.
On some systems, the long-term scheduler may not be available or minimal. Time-sharing
operating systems have no long term scheduler. When a process changes the state from new
to ready, then there is use of long-termscheduler.
Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next. Short-term schedulers are faster than long-term schedulers.
A running process may become suspended if it makes an I/O request. A suspended processes
cannot make any progress towards completion. In this condition, to remove the process from
memory and make space for other processes, the suspended process is moved to the
secondary storage. This process is called swapping, and the process is said to be swapped out
or rolled out. Swapping may be necessary to improve the process mix.
Context Switch
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 systemfeatures.
When the scheduler switches the CPU from executing one process to execute another, the
state from the current running process is stored into the process control block. After this, the
state for the process to run next is loaded from its own PCB and used to set the PC, registers,
etc. At that point, the second process can start executing.
Program Counter
Schedulinginformation
Base and limit registervalue
Currently used register
ChangedState
What is Thread?
A thread is a flow of execution through the process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its current
working variables, and a stack which contains the execution history.
A thread shares with its peer threads few information like code segment, data segment and
open files. When one thread alters a code segment memory item, all other threads see that.
A thread is also called a lightweight process. Threads provide a way to improve application
performance through parallelism. Threads represent a software approach to improving
performance of operating system by reducing the overhead thread is equivalent to a classical
process.
Each thread belongs to exactly one process and no thread can exist outside a process. Each
thread represents a separate flow of control. Threads have been successfully used in
implementing network servers and web server. They also provide a suitable foundation for
parallel execution of applications on shared memory multiprocessors. The following figure
shows the working of a single-threaded and a multithreaded process.
Advantages of Thread
Advantages
Kernelcansimultaneouslyschedulemultiplethreadsfromthesameprocessonmultiple
processes.
If one thread in a process is blocked, the Kernel can schedule another thread ofthe
same process.
Kernel routines themselves can bemultithreaded.
Disadvantages
Kernel threads are generally slower to create and manage than the userthreads.
Transfer of control from one thread to another within the same process requiresa
mode switch to theKernel.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread facility.
Solaris is a good example of this combined approach. In a combined system, multiple threads
within the same application can run in parallel on multiple processors and a blocking system
call need not block the entire process. Multithreading models are three types
Many to manyrelationship.
Many to onerelationship.
One to one relationship.
Many to Many Model
The many-to-many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads.
The following diagram shows the many-to-many threading model where 6 user level threads
are multiplexing with 6 kernel level threads. In this model, developers can create as many user
threads as necessary and the corresponding Kernel threads can run in parallel on a
multiprocessor machine. This model provides the best accuracy on concurrency and when a
thread performs a blocking system call, the kernel can schedule another thread for execution.
If the user-level thread libraries are implemented in the operating system in such a way that
the system does not support them, then the Kernel threads use the many-to-one relationship
modes.
Disadvantage of this model is that creating user thread requires the corresponding Kernel
thread. OS/2, windows NT and windows 2000 use one to one relationship model.
UNIT ‐ III
Inter-process Communication: Critical Section, Race Conditions, Mutual Exclusion, Hardware
Solution, Strict Alternation, Peterson’s Solution, The Producer\Consumer Problem,
Semaphores, Event Counters, Monitors, Message Passing, Classical IPC Problems: Reader’s &
Writer Problem, Dinning Philosopher Problem etc.
Deadlocks: Definition, Necessary and sufficient conditions for Deadlock, Deadlock Prevention,
Deadlock Avoidance: Banker’s algorithm, Deadlock detection and Recovery.
Inter-process Communication:
Informationsharing:Sincesomeusersmaybeinterestedinthesamepieceofinformation(for
example, a shared file), you must provide a situation for allowing concurrent access to that
information.
Computation speedup: If you want a particular work to run fast, you must break it into sub-
taskswhereeachofthemwillgetexecutedinparallelwiththeothertasks.Notethatsucha speed-
up can be attained only when the computer has compound or various processing elements
like CPUs or I/Ochannels.
Modularity: You may want to build the system in a modular way by dividing thesystem
functions into split processes orthreads.
Convenience: Even a single user may work on many tasks at a time. For example, a user may
be editing, formatting, printing, and compiling inparallel.
1. shared memoryand
2. message passing.
Interprocess communication (IPC) usually utilizes shared memory that requires communicating
processes for establishing a region of shared memory. Typically, a shared-memory region
resides within the address space of any process creating the shared memory segment. Other
processes that wish for communicating using this shared-memory segment must connect it to
their address space.
while(1){
shared_buff[free_index] = nextProduced;
free_index = (free_index + 1) mod buff_max;
}
while(1){
nextConsumed = shared_buff[full_index];
full_index = (full_index + 1) mod buff_max;
}
In the above code, The producer will start producing again when the (free_index+1) mod buff
max will be free because if it it not free, this implies that there are still items that can be
consumed by the Consumer so there is no need to produce more. Similarly, if free index and full
index points to the same index, this implies that there are no item to consume.
The message size can be of fixed size or of variable size. if it is of fixed size, it is easy for OS
designer but complicated for programmer and if it is of variable size then it is easy for
programmer but complicated for the OS designer. A standard message can have two
parts: header andbody.
The header part is used for storing Message type, destination id, source id, message length and
control information. The control information contains information like what to do if runs out of
buffer space, sequence number, priority. Generally, message is sent using FIFO style.
messages that can reside in it temporarily for which Every link has a queue associated with it
which can be either of zero capacity or of bounded capacity or of unbounded capacity. In zero
capacity, sender wait until receiver inform sender that it has received the message. In non-zero
capacity cases, a process does not know whether a message has been received or not after the
send operation. For this, the sender must communicate to receiver explicitly. Implementation
of the link depends on the situation, it can be either a Direct communication link or an In-
directed communication link.
Direct Communication links are implemented when the processes use specific process
identifier for the communication but it is hard to identify the sender ahead of time.
For example: the print server.
In-directed Communication is done via a shred mailbox (port), which consists of queue of
messages. Sender keeps the message in mailbox and receiver picks them up.
Producer Code:
void Producer(void){
int item;
while(1){
receive(Consumer, &m);
item = produce();
build_message(&m , item ) ;
send(Consumer, &m);
}
}
Consumer Code:
void Consumer(void){
int item;
Message m;
while(1){
receive(Producer, &m);
item = extracted_item();
send(Producer, &m);
consume_item(item);
}
}
The above three methods will be discussed later article as all of them are quite conceptual and
deserve their own separate articles.
Mutual Exclusion
The mutual exclusion condition must hold. That is, at least one resource must be
nonsharable. Sharable resources, in contrast, do not require mutually exclusive access
and thus cannot be involved in a deadlock. Read-only files are a good example of a
sharable resource.
No Preemption
The third necessary condition for deadlocks is that there be no preemption of resources
that have already been allocated. To ensure that this condition does not hold, we can
use the following protocol. If a process is holding some resources and requests another
resource that cannot be immediately allocated to it (that is, the process must wait), then
all resources the process is currently holding are preempted.
CircularWait
The fourth and final condition for deadlocks is the circular-wait condition. One way to
ensure that this condition never holds is to impose a total ordering of all resource types
and to require that each process requests resources in an increasing order of
enumeration
DEADLOCK AVOIDANCE
A deadlock-avoidance algorithm dynamically examines the resource-allocation state to
ensure that a circular-wait condition can never exist. The resourceallocation state is
defined by the number of available and allocated resources and the maximum demands
of the processes.
Safe State
BANKER’S ALGORITHM
The resource-allocation-graph algorithm is not applicable to a resourceallocation system
with multiple instances of each resource type. The deadlockavoidance algorithm that we
describe next is applicable to such a system but is less efficient than the resource-
allocation graph scheme. This algorithm is commonly known as the banker’s algorithm.
DEADLOCK DETECTION
If a system does not employ either a deadlock-prevention or a deadlockavoidance
algorithm, then a deadlock situation may occur. In this environment, the system may
provide:
• An algorithm that examines the state of the system to determine whether a deadlockhas
occurred
• An algorithm to recover from thedeadlock.
Process Termination
To eliminate deadlocks by aborting a process, we use one of two methods. In both
methods, the system reclaims all resources allocated to the terminated processes.
• Abort all deadlocked processes. This method clearly will break the deadlock cycle, but
at great expense. The deadlocked processes may have computed for a long time, and the
results of these partial computations must be discarded and probably will have to be
recomputedlater.
• Abort one process at a time until the deadlock cycle is eliminated. This method incurs
considerable overhead, since after each process is aborted, a deadlock-detection
algorithm must be invoked to determine whether any processes are stilldeadlocked.
Resource Preemption
To eliminate deadlocks using resource preemption, we successively preempt some
resources from processes and give these resources to other processes until the deadlock
cycle is broken.
PROTECTION
Protection refers to a mechanism for controlling the access of programs, processes, or
users to the resources defined by a computer system.
GOALS OF PROTECTION
Protection can improve reliability by detecting latent errors at the interfaces between
component subsystems. mechanisms are distinct from policies. Mechanisms determine
how something will be done; policies decide what will be done. The separation of policy
and mechanism is important for flexibility. Policies are likely to change from place to
place or time to time.
PRINCIPLES OF PROTECTION
a guiding principle can be used throughout a project, such as the design of an operating
system. Following this principle simplifies design decisions and keeps the system
consistent and easy to understand. A key, time-tested guiding principle for protection is
the principle of least privilege. It dictates that programs, users, and even systems be
given just enough privileges to perform their tasks.
DOMAIN OF PROTECTION
A computer system is a collection of processes and objects. By objects, we mean both
hardware objects (such as the CPU, memory segments, printers, disks, and tape drives)
and software objects (such as files, programs, and semaphores). 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 operations. Objects are essentially
abstract data types.
Global Table
The simplest implementation of the access matrix is a global table consisting of a set of
ordered triples <domain, object, rights-set>. Whenever an operation M is executed on an
object Oj within domain Di , the global table
is searched for a triple <Di , Oj , Rk>, with M ∈ Rk . If this triple is found, the operation is
allowed to continue; otherwise, an exception (or error) condition is raised.
Access Lists for Objects
Each column in the access matrix can be implemented as an access list for one object, as
described in Obviously, the empty entries can be discarded. The resulting list for each
object consists of ordered pairs <domain, rights-set>, which define all domains with a
nonempty set of access rights for that object.
ACCESS CONTROL
Each file and directory is assigned an owner, a group, or possibly a list of users, and for
each of those entities, access-control information is assigned. A similar function can be
Capability-Based Systems
In this section, we survey two capability-based protection systems. These systems differ
in their complexity and in the types of policies that can be implemented on them.
An Example: Hydra
Hydra is a capability-based protection system that provides considerable flexibility. The
system implements a fixed set of possible access rights, including such basic forms of
access as the right to read, write, or execute a memory segment. In addition, a user (of
the protection system) can declare other rights. The interpretation of user-defined rights
is performed solely by the user’s program, but the system provides access protection for
the use of these rights, as well as for the use of system-defined rights. These facilities
constitute a significant development in protection technology
The second kind of capability is the so-called software capability, which is protected, but
not interpreted, by the CAP microcode. It is interpreted by a protected (that is,
privileged) procedure, which may be written by an application programmer as part of a
subsystem.
LANGUAGE-BASED PROTECTION
The designers of protection systems have drawn heavily on ideas that originated in
programming languages and especially on the concepts of abstract data types and objects
Compiler-Based Enforcement
Protection in Java
Because Java was designed to run in a distributed environment, the Java virtual
MEMORY MANAGEMENT:
In general, to rum a program, it must be brought into memory.
Input queue – collection of processes on the disk that are waiting to be brought into
memory to run the program. User programs go through several steps before being run
Address binding: Mapping of instructions and data from one address to
another address in memory. Three different stages of binding:
Compile time: Must generate absolute code if memory location is known in prior.
Loadtime: Must generate relocatable code if memory location isnot
known at compile time Execution time: Need hardware support for
address maps (e.g., base and limitregisters).
Logical vs. Physical Address Space
memory unit.
scheme"
generated by a user process. The user program deals with logical addresses; it
Useful when large amounts of code are needed to handle infrequently occurring cases
Linking postponed until execution time & is particularly useful for libraries
Small piece of code called stub, used to locate the appropriate memory- resident
library routine or function. Stub replaces itself with the address of the routine, and
executes the routine
Operating system needed to check if routine is in processes’ memory address
Shared libraries: Programs linked before the new library was installed will continue
A process can be swapped temporarily out of memory to a backing store (SWAP OUT)and
then brought back into memory for continued execution (SWAP IN).
Backing store – fast disk large enough to accommodate copies of all memory
images for all users & it must provide direct access to these memory images
Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-
priority process is swapped out so higher-priority process can be loaded and executed
Transfer time: Major part of swap time is transfer time. Total transfer time is directly
proportional to the amount of memory swapped.
Example: Let us assume the user process is of size 1MB & the backing store is a standard
hard disk with a transfer rate of 5MBPS.
Transfer time = 1000KB/5000KB per second
= 1/5 sec = 200ms
Contiguous Allocation
Each process is contained in a single contiguous
section of memory. There are two methods namely:
As processes complete and leave they create holes in the main memory.
Hole – block of available memory; holes of various size are scattered throughout memory.
NOTE: First-fit and best-fit are better than worst-fit in terms of speed
and storage utilization Fragmentation:
o External Fragmentation – This takes place when enough total memory space exists to
satisfy a request, but it isnot contiguous i.e, storage is fragmented into a large numberof
small holes scattered throughout the mainmemory.
o Each process has a segment table associated with it, which thedispatcher
uses to definethe hardware segment table when this process is given the
CPU.
Segments are shared when entries in the segment tables of two different processes
pointto the same physicallocation.
The IBM OS/ 2.32 bit version is an operating system running on top of the Intel 386
architecture. The 386 uses segmentation with paging for memory management. The
Each entry in the LDT and GDT consist of 8 bytes, with detailed information about a
particular segment including the base location and length of the segment.
The logical address is a pair (selector, offset) where the selector is a16-bit number:
Where s designates the segment number, g indicates whether the segment is in the GDT or
LDT, and p deals with protection. The offset is a 32-bit number specifying the location of the
byte within the segment in question.
o The base and limit information about the segment in question are used to
generate a linear-address.
o First, the limit is used to check for address validity. If the address is not valid, a
memory fault is generated, resulting in a trap to the operating system. If it is
valid, then the value of the offset is added to the value of the base, resulting in a
32-bit linear address. This address is then translated into a physicaladdress.
o The linear address is divided into a page number consisting of 20 bits, and a
page offset consisting of 12 bits. Since we page the page table, the page
number is further divided into a 10-bit page directory pointer and a10-bit
o To improve the efficiency of physical memory use. Intel 386 page tablescan
be swapped to disk. Inthis case, an invalid bit is used in the page directory
entry to indicate whether the table to which the entry is pointing is in
memory or ondisk.
If the table is on disk, the operating system can use the other 31 bits to specify the disk location
of thetable; the table then can be brought into memory on demand.
• Itisamemorymanagementschemethatpermitsthephysical
address space of a process to benoncontiguous.
• Itavoidstheconsiderableproblemoffittingthevaryingsizememory
chunks on to the backingstore.
(i) BasicMethod:
Divide logical memory into blocks of same size called “pages”. o Divide physical memory into
fixed-sized blocks called “frames” o Page size is a power of 2, between 512 bytes and 16MB.
□ Pagenumber(p)–usedasanindexintoapagetablewhichcontains base
□ Page offset (d) –combined with base address to define the physical address
i.e.,
Physical address = base address + offset
Demand Paging
Page Replacement
Write the victim page to the disk, change the page & frame tables accordingly
1. Read the desired page into the (new) free frame. Update the page and frametables.
File Concept:
A file is a named collection of related information that is recorded on secondary
storage.
Examples of files:
Access Methods
1. SequentialAccess
The simplest access method is sequential access. Information in the file is processed in order,
one record after the other. This mode of access is by far the most common; for example, editors
and compilers usually access files in this fashion.
• The bulk of the operations on a file is reads and writes. A read operation reads the
next portion of the file and automatically advances a file pointer, which tracks the I/O
location. Similarly, a write appends to the end of the file and advances to the end of
the newly written material (the new end of file). Such a file can be reset to the
beginning and, on some systems, a program may be able to skip forward or backward
n records, for some integer n-perhaps only for n=1. Sequential access is based on a
tape model of a file, and works as well on sequential-access devices as it does on
random – accessones.
2. DirectAccess
• Another method is direct access (or relative access). A file is made up of fixed length
logical records that allow programs to read and write records rapidly in no particular
order. The direct- access methods is based on a disk model of a file, since disks allow
random access to any fileblock.
• For direct access, the file is viewed as a numbered sequence of blocks or records. A
direct-access file allows arbitrary blocks to be read or written. Thus, we may read
block 14, then read block 53, and then write block7. There are no restrictions on the
order of reading or writing for a direct-accessfile.
•
Direct – access files are of great use for immediate access to large amounts of information.
Database is often of this type. When a query concerning a particular subject arrives, we
compute which block contains the answer, and then read that block directly to provide the
desired information.
Directory and Disk Structure
1. Single – LevelDirectory
• Disadvantage:
➢ When the number of files increases or when the system hasmore
than one user, since all filesare in the same directory, they must have unique
names.
2. Two – LevelDirectory
• Inthetwo leveldirectorystructures,eachuserhasherownuserfiledirectory(UFD).
• When a user job starts or a user logs in, the system’s master file directory(MFD)
is searched. TheMFDis
indexed by user name or account number, and each entry points to the UFD for
thatuser.
• When a user refers to a particular file, only his own UFD issearched.
• Thus, different users may have files with the samename.
• Although the two – level directory structure solves the name-collisionproblem
Disadvantage:
➢ Users cannot create their ownsub-directories.
3. Tree – StructuredDirectory
• A tree is the most common directorystructure.
• Thetreehasarootdirectory.Everyfileinthe system hasauniquepathname.
• Apathnameisthepathfromtheroot,through allthe subdirectoriestoaspecifiedfile.
• A directory (or sub directory) contains a set of files or subdirectories.
• A directory is simply another file. But it is treated in a specialway.
• All directories have the same internalformat.
• One bit in each directory entry defines the entry as a file (0) or as asubdirectory(1).
• Special system calls are used to create and deletedirectories.
• Path names can be of two types: absolute path names or relative pathnames.
• Anabsolutepathnamebeginsattherootandfollowsapathdowntothespecified file,
giving thedirectory
• The system either can allow user to access the file of other users by default, or it
mayrequire that a user specifically grant access to thefiles.
• These are the issues of access control andprotection.
• To implementing sharing and protection, the system must maintainmore
file and directory attributes than a on a single-usersystem.
• The owner is the user who may change attributes, grand access, and has the most
control over the fileor
directory.
• When a user logs in to the system, the authentication stage determines the
appropriate user ID for the user. That user ID is associated with all of user’s
processes and threads. When they need to be user readable, they are translated,
back to the user name via the user name list. Likewise, group functionality can be
implemented as a system wide list of group names andgroupidentifiers.
• Every user can be in one or more groups, depending upon operating system design
decisions. The user’sgroup Ids is also included in every associated process and
thread.
b) Distributed Informationsystems:
• Distributed information systems, also known as distributed naming
service, have been devised toprovide a unified access to the information needed
for remotecomputing.
• Domain name system (DNS) provides host-name-to-network address
translations for theirentire Internet (including the World WideWeb).
• Before DNS was invented and became widespread, files containing the
same information weresent
via e-mail of ftp between all networked hosts.
c) FailureModes:
• Redundant arrays of inexpensive disks (RAID) can prevent the loss of
a disk from resulting in the loss ofdata.
• Remote file system has more failure modes. By nature of the complexity
of networking system and the required interactions between remote machines,
many more problems can interfere with the proper operation of remote file
systems.
(i) UNIXSemantics:
The UNIX file system uses the following consistency semantics:
1. Writes to an open file by a user are visible immediately to other usersthat
have this file open at thesametime.
2. One mode of sharing allows users to share the pointer of current location
intothefile.Thus,theadvancingofthepointerbyoneuseraffectsallsharing users.
(ii) SessionSemantics:
The Andrew file system (AFS) uses the following consistency semantics:
1. Writes to an open file by a user are not visible immediately toother
users that have the same file opensimultaneously.
2. Once a file is closed, the changes made to it are visible only insessions
starting later. Already open instances of the file do not reflect this
change.
File Protection
(i) Need for fileprotection.
• When information is kept in a computer system, we want to keep it safe from physical
damage
(reliability) and improper access (protection).
• To condense the length of the access control list, many systems recognize three
classifications of users in connection with eachfile:
• Disk provide the bulk of secondary storage on which a file system ismaintained.
• Characteristics of adisk:
1. Theycanberewritten inplace,itispossibletoreadablockfromthedisk,to modify
the block and towrite it back into the sameplace.
2. They can access directly any given block of information to thedisk.
• To produce an efficient and convenient access to the disk, the operating
system imposes one or more file system to allow the data to be stored,located
and retrievedeasily.
• The file system itself is generally composed of many different levels. Each level inthe
designuses the features of lower level to create new features for use by higher
levels.
Layered File System
• The I/O control consists of device drivers and interrupt handlers to
transferinformationbetweenthemainmemoryandthedisksystem.
• The basic file system needs only to issue generic commands to the
appropriate device driver to read and write physical blocks on the disk. Each
physical block is identified by its numeric disk address (forexample, drive –1,
cylinder 73, track 2, sector10)
Directory Implementation
1. LinearList
• Thesimplestmethodofimplementingadirectoryistousealinearlistoffile names
with pointer to thedata
blocks.
2. HashTable
• In this method, a linear list stores the directory entries, but a hash data structure is also
used.
• The hash table takes a value computed from the file name and returns apointer
to the file name inthelinear
list.
• The major difficulties with a hash table are its generally fixed size andthe
dependence ofthe hash function on thatsize.
Allocation Methods
• The main problem is how to allocate space to these files so that disk space isutilized
effectively and files.can be accessedquickly.
• There are three major methods of allocating diskspace:
1. ContiguousAllocation
2. LinkedAllocation
3. IndexedAllocation
1. ContiguousAllocation
• The contiguous – allocation method requires each file to occupy a set of contiguous blocks
on thedisk.
Disadvantages:
1. Finding space for a newfile.
• The contiguous disk space-allocation problem suffer from the problem of
external fragmentation. As file are allocated and deleted, the free diskspace
is broken into chunks. It becomes a problem when the largest contiguous
chunk is insufficient for a request; storage is fragmented into a number of
holes, no one ofwhich is large enough to store thedata.
• If we allocate too little space to a file, we may find that file cannot be
extended. The other possibility is to find a larger hole, copy the contents of the
file to the new space, and release the previous space. This seriesof actionsmay
be repeated as long as space exists, although it can be time – consuming.
However, in this case, the user never needs to be informed explicitly about
what is happening ; the system continues despite the problem, although more
and moreslowly.
• Even if the total amount of space needed for a file is known in advance pre-
allocation may beinefficient.
• A file that grows slowly over a long period (months or years) must be allocated
enough space for its final size, even though much of that space may be unused for
a long time the file, therefore has a large amount of internalfragmentation.
To overcome these disadvantages:
• Use a modified contiguous allocation scheme, in which a contiguous chunk of
space called as an extent is allocated initially and then, when that amount is not
large enough another chunk of contiguous space an extent is added to the initial
allocation.
• Internal fragmentation can still be a problem if the extents are too
large, and external fragmentation can be a problem as extents of varying
sizes are allocated anddeallocated.
• Each block contains a pointer to the next block. These pointers are not made availableto
theuser.
• There is no external fragmentation with linked allocation, and any free block on thefree
space list can beused to satisfy arequest.
• The size of a file does not need to the declared when that file is created. A file can
continue to grow as long as free blocks are available consequently, it is never necessaryto
compactsdisk