Os PDF
Os PDF
♥ management of processes
Multiprogramming System
Parallel System
Distributed System
Jobs are storing in a queue until the computer is ready to deal with them
Jobs are processed in the order of first come first served fashion.
OS keeps a number of jobs in memory and executes them without any manual information.
When job completes its execution, its memory is released and the output for the job gets copied
into an output spool for later printing or processing.
Advantages of Batch systems:
♥ The operating system switches jobs in and out of the processor according to priority
♥ The processor is so fast that it seems that many jobs are being processed at the same time
♥ The operating system picks and executes one of the jobs in the memory. The job in execution
may have to wait for some task, such as an I/O operation to complete
Multi-programmed system
Advantages of Multiprogramming System:
♥ Time sharing system were developed t provides interactive use of computer system
♥ A time-share operating system allows many users to share the computer resource
simultaneously.
♥ The CPU executes multiple jobs by switching among themselves, but the switches occur so
frequently that the users can interact with each program while it is running
♥ In a time sharing system, each process executes only for a short-time for each user
♥ Similar to multiprogramming, even in time-sharing systems, several jobs are kept simultaneously
in memory
Advantages of Time-Sharing System.
x Problem of reliability.
4) Parallel System:
Multiprocessor systems.
To execute using multiple CPUs, a problem is broken into discrete parts that can be solved
concurrently.
They are called tightly coupled systems due to high degree of resource sharing.
Increased throughput as by increasing the number of processors, hope to get more work done in less
time
Increase reliability as functions are distributed properly among several processors, then the failure
of one processor will not halt the system.
x Implementation is complex
Access to a shared resource increases computation speed, functionality, data availability and
reliability
Each processor communicates with one another through various communication lines such as
communication lines. These systems are referred to as loosely coupled systems or distributed
system.
Distributed systems also consist of multiple computers but differ from networked systems in that
the multiple computers are transparent to the user. Often there are redundant resources and a
sharing of the workload among the different computers.
Reliability-if one site fails in a distributed system, then the remaining sites can continue operating.
Computation speedup as computations can be partitioned into sub-computations which can be run
concurrently on various sites in a distributed system.
x Implementation is complex.
Systems used to control machinery, scientific instruments and industrial systems are real time
systems.
A real time system has well-defined, fixed time constraints. Processing must be done within the
defined constraints, or the system will fail.
Guided missile systems and medical monitoring equipment are examples of real time operating
systems.
Hard real time systems: guarantee that critical tasks will complete on time. Safety-critical systems
are typically hard real-time systems.
Soft real-time systems: are less restrictive, simply providing that a critical real time tasks get
priority over the others and retains that priority until it completes.
Advantages of Real Time Systems:
Memory management in real time systems is comparatively less demanding than in other types of
operating systems.
With spooling all process can access the resource without waiting
The spool is processed in ascending order, working on the basis of a FIFO (first in, first out)
algorithm.
For example, in printer spooling, the documents/files that are sent to the printer are first stored in
the memory or printer spooler. Once the printer is ready, it fetches the data from that spool and
prints it.
Advantages of Spooling:
It overlaps the I/O operation of one job with the computation of other jobs. For example, while
reading the input of one job, the spooler may be printing the output of a different job.
The operating system is responsible for the following activities in connections with file
management:
♥ Program execution – system capability to load a program into memory and to run it.
♥ I/O operations – since user programs cannot execute I/O operations directly, the operating
system must provide some means to perform I/O.
♥ File-system manipulation – program capability to read, write, create, and delete files.
♥ Error detection – ensure correct computing by detecting errors in the CPU and memory hardware,
in I/O devices, or in user programs.
♥ User Interface- with the help of which the user submits his programs.
Additional functions exist not for helping the user, but rather for ensuring efficient system operations.
♥ Memory management -The o/s keeps track of the memory, what parts are use and by whom.
♥ Process management - The o/s keeps track of processors and the status of processes. It decides
who will have a chance to use the processor.
♥ Device management -The o/s keeps track of the devices, channels, control units and decides what
is an efficient way to allocate the device
♥ Resource allocation – allocating resources to multiple users or multiple jobs running at the same
time.
♥ Accounting – keep track of and record which users use how much and what kinds of computer
resources for account billing or for accumulating usage statistics.
♥ Protection & Security – ensuring that all access to system resources is controlled. Security means
to ensure that unauthorized access is restricted.
System Calls: (5M-2012)
♥ System call act as an interface between a process and the operating system
♥ Operating system provide the services to the user by using system call
System Models:
Process State: (5M-2014)(6M-2015)
As a process executes, it changes state. The state of a process is defined as the current activity of
the process.
4. Waiting: The process is waiting for some event to occur(wait for user input or file to open)
♥ Process State.: The state may be new, ready, running, Waiting or terminated.
♥ Program Counter.: The counter indicates the address of the next instruction to be executed
for this process.
♥ CPU Registers.: Whenever a processor switches over from one process to another, information
about current status of the old process is saved in the register
♥ I/O Status Info.: The information includes the list of I/O devices allocated to this process, a
list of open files and so on.
♥ Accounting Information: amount of CPU and real time used, time limits, job or process numbers
and so on.
♥ Memory limits: the value of the base and limit registers the page table and memory details
Schedulers: (9M-2011)
Schedulers are special system software which handles 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 determines which programs are admitted to the system for processing.
Job scheduler selects processes from the queue and loads them into memory for execution.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O
bound and processor bound.
On some systems, the long term scheduler may not be available or minimal. Time-sharing
operating systems have no long term scheduler.
When process changes the state from new to ready, then there is use of long term scheduler.
SHORT-TERM SCHEDULER:
It is also called CPU scheduler.
Main objective is increasing system performance in accordance with the chosen set of criteria.
CPU scheduler selects process among the processes that are ready to execute and allocates CPU
to one of them.
Short term scheduler also known as dispatcher, execute most frequently and makes the fine
grained decision of which process to execute next.
MEDIUM-TERM SCHEDULER:
A running process may be suspended because of I/O request. Such a suspended process is then
removed from main memory and stored in secondary memory. This process is called swapping.
Medium term scheduling is part of the swapping. It removes the processes from the memory.
This is done because there is a limit on the number of active processes that can reside in main
memory.
Therefore, a suspended process is swapped-out from main memory.
At some later time, the process can be swapped-in into the main memory.
Speed is lesser than short Speed is fastest among Speed is in between both short
2
term scheduler other two and long term scheduler.
It selects processes from pool It selects those processes It can re-introduce the process
5 and loads them into memory which are ready to into memory and execution can be
for execution execute continued.
Context Switch: (5M-2012)
When one process is running on a CPU and another needs to run on the same CPU, there is
need to switch between the processes. This is called a context switch (or a “state” save
and “state” restore).
The context is represented in the PCB of the process. It includes the value of CPU registers,
the process state, and memory management information.
Switching the CPU to another process requires performing a state save of the current process
and a state restore of a different process.
When a context switch occurs, the kernel saves the context of the old process in its PCB and
load the save context of the new process scheduled to run. Context-switch time is pure overhead
as the system does no useful work while switching.
Speed of context switch varies from system to system, depending on memory speed, number of
registers that must be copied, and the existence of special instructions.
CPU Scheduler:
Selects the process from the processes in memory that are ready to execute, and allocates the CPU to
one of them.
4. Terminates.
Dispatcher: (2M-2015)
The dispatcher is the module that gives control to the CPU to the process selected by the short-term
scheduler; this function involves:
switching context
jumping to the proper location in the user program to restart that program
Dispatch latency: The Time it takes for the dispatcher to stop one process and start another running.
Types of Scheduling: (5M-2014)(5M-2015)
Once the CPU is given to a process, it The CPU can be taken away
cannot be taken away from that process
Shorter jobs must wait for completion of Shorter jobs need not wait
longer jobs
Suitable for batch processing Suitable for real time and interactive time sharing
systems
It occurs when the process either switches It occurs when the process either switches from
from running state to waiting state or when running state to ready state or from waiting state
it terminates to ready state
The CPU is often idle during an I/O request Maximum utilization of CPU
or invocation of wait for the termination of
one of the child process
Job is completed according to the allocated Completion time of the process in execution cannot
time be completed accurately
Priority Scheduling
The implementation of the FCFS policy is easily managed with a FIFO queue.
When a process enters the ready queue, its PCB is linked onto the tail of the queue.
When the CPU is free, it is allocated to the process at the head of the queue.
Requests are scheduled in the order in which they arrive in the system.
The FCFS algorithm is non-preemptive. Once the CPU has been allocated to a process, that
process keeps the CPU until it releases the CPU, either by termination or by requesting I/O.
The average waiting time under the FCFS policy is quite long.
Advantages:
-------------------------------------------------------------------------
P1 24
P2 3
P3 3
-------------------------------------------------------------------------
Process Burst Time
P1 20
P2 4
P3 3
-------------------------------------------------------------------------
It associates with each process, the length of its next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.
If two processes have the same length of next CPU burst, FCFS scheduling is used.
Two schemes:
Non preemptive – once CPU given to the process it cannot be preempted until completes
its CPU burst.
Preemptive – if a new process arrives with CPU burst length less than remaining time of
current executing process, preempt. This scheme is known as the Shortest-Remaining-
Time-First (SRTF).
SJF is optimal – gives minimum average waiting time for a given set of processes.
Advantages:
Preference will be given for shorter jobs and hence average waiting time reduces.
Disadvantages:
-------------------------------------------------------------------------
Consider the following set of processes that arrive at time 0 with the length of the CPU burst time in
milliseconds:
= (0 + 3 + 9 + 16 ) / 4
= 28 / 4
= 7 milliseconds
-------------------------------------------------------------------------
Consider the following set of processes that arrive at time 0 with the length of the CPU burst time in
milliseconds:
P1 5
P2 10
P3 6
P4 2
-------------------------------------------------------------------------
Consider the following set of processes. These processes arrived in the ready queue at the times given
in the table:
-------------------------------------------------------------------------
Consider the following example:
P1 0 10
P2 1 4
P3 2 8
P4 3 6
-------------------------------------------------------------------------
Priorities may be static or dynamic. Their initial values are assigned by the user or the system
at the process creation time.
A preemptive priority scheduling algorithm will preempt the CPU if the priority of the newly
arrived process is higher than the priority of the currently running process.
A non-preemptive priority scheduling algorithm will simply put the new process at the head of
the ready queue.
Disadvantage:
x Implementation is difficult.
x Leads to situations in which low priority process wait indefinitely for high priority processes.
-------------------------------------------------------------------------
Each and every process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds.
After this time has elapsed, the process is preempted and added to the end of the ready queue.
The ready queue is treated as a circular queue. The CPU scheduler goes around the ready queue,
allocating CPU to each process for a time interval of up to 1 time quantum.
If there are n processes in the ready queue and the time quantum is q, then each process gets
1/n of the CPU time in chunk of at most q time units at once. No process waits more than (n-1) *
q time units.
-------------------------------------------------------------------------
Consider the example of a set of processes with arrive time 0, in the order P1, P2,: ….P5. The CPU burst
time and priority given by
-------------------------------------------------------------------------
Consider the following set of processes that arrive at time 0 with the length of the CPU burst time in
milliseconds:
= (7 + 8 + 4) / 3
= 19 / 3
= 6.33 milliseconds
-------------------------------------------------------------------------
Consider the example of 3 processes P1, P2 and P3 with the following CPU time , given time-slice=4 ms
-------------------------------------------------------------------------
5)) MULTILEVEL QUEUE SCHEDULING:
A multilevel queue scheduling algorithm partitions the ready queue into several separate queues.
The processes are permanently assigned to one queue, based on some property of the process,
such as memory size, process priority or process type.
One method is to assign time-slice to each queue, with which it can schedule the various
processes in its queue. For example, interactive processes may be assigned 80% of the CPU time
and the background processes may be given 20% of the CPU.
Another method is to execute the high priority queues first and then process the lower priority
queues.
6)) Multilevel Feedback Queue
A process can move between the various queues; aging can be implemented this way.
Three queues:
• Q2 – FCFS
Scheduling:
• A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds.
If it does not finish in 8 milliseconds, job is moved to queue Q1.
• At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not
complete, it is preempted and moved to queue Q2.
number of queues
Deterministic modeling
Queuing Models
Simulations
Implementation
1) Deterministic modeling
Deterministic modeling – Takes a particular predetermined workload and defines the performance of
each algorithm for that workload.
Advantages:
Disadvantages:
x It needs exact numbers for input and its answers apply only those cases
2) Queuing Models
Queuing models can be used to examine the distribution of CPU and I/O bursts by a formula giving
the probability of a particular CPU burst. In addition the following computations are also possible.
Advantages:
Useful when the number of processes running on the system is not static.
Disadvantages:
For more accurate results, it may be necessary to use process information from a real system.
Advantages:
Disadvantages:
4) IMPLEMENTATION:
Implementation involves evaluating an algorithm by coding it, use it in the operating system and
see its working. Implementation method puts the algorithm in the real time system under
operating condition.
Disadvantages:
SEMAPHORE: (2M-2012)(8M-2014)(7M-2015)(2M-2010)
Wait() Signal ()
wait(Semaphore s) signal(Semaphore s)
{ {
while s<=0 ; S++;
s--; }
}
TYPES OF SEMAPHORES: (2M-2011)
Binary Semaphore:
A semaphore whose variable is allowed to take only values of 0(busy) and 1 (free) is called binary
semaphore
Binary semaphores are known as mutex locks, as they provide mutual exclusion.
They are used to acquire locks.
When a resource is available, the process in charge set the semaphore to 1 else 0.
They can be used to solve critical-section problem for multiple processes.
Counting Semaphore:
May have value to be greater than one, typically used to allocate resources from a pool of
identical resources.
First the semaphore is initialized to the number of resources available
Each process that wishes to use a resource performs a wait ( ) operation on the semaphore
(thereby decrementing the count)
When the process releases the resources, it performs a signal ( ) operation (thereby
incrementing the count)
When the count for the semaphore becomes 0, all the resources are used and any process requesting
for the resource is blocked until the count becomes greater than 0
Deadlock: (2m-2014)(2M-2010)
Deadlock can be defined as permanent blocking of a set of Processes that either compete for system
resources or communicate with each other.
Example:
1. System has 2 tape drives.
2. P1 and P2 each hold one tape drive and each needs another one.
DEADLOCKS CHARACTERIZATION
NECESSARY CONDITION:
Deadlock can occur if four conditions hold simultaneously in a system.
Mutual exclusion: means only one process at a time can use a resource.
Hold and wait: a process holding at least one resource is waiting to acquire additional
resources held by other processes.
No preemption: a resource can be released by the process holding it, only after that process
has completed its task.
Circular wait: A circular chain of two or more processes must exist such that each of them is
waiting for a resource held by the next number of the chain shown in figure.
Deadlocks can be described more precisely in terms of directed graph called a system resource –
allocation graph.
A set of vertices V and a set of edges E.
V is partitioned into two types:
P = {P1, P2, …, Pn}, the set of all active processes in the system.
R = {R1, R2, …, Rm}, the set consisting of all resource types in the system.
A directed edge from process Pi to resource type Rj denoted by Pi Rj signifies that process Pi
has requested an instance of resource type Rj and is currently waiting for that resource. This
edge is called a request edge.
A directed edge from resource type Rj to process Pi, denoted by Rj Pi, signifies that an
instance of resource type Rj has been allocated to process Pi and is called an assignment edge.
Pictorially, process Pi is denoted as a circle and each resource type Rj as a square.
If a resource has more than one instance, then each instance is represented as a dot within the
square
Once the process finishes accessing the resource, it releases it and the assignment edge is
deleted.
Example-RESOURCE ALLOCATION GRAPH
Process P1 is holding an instance of resource R2, is waiting for an instance of resource type R1
Process P2 is holding an instance of R1 and R2, is waiting for an instance of resource type R3
Process P3 is holding an instance of R3
Suppose the process P3 requests an instance of resource type R2, since no resource instance is
currently available, a request edge P3 --> R2 is added to the graph.
Methods for Handling Deadlocks: (2M-2015)
Deadlock Prevention
Deadlock Avoidance.
Recovery from Deadlock
By making sure that one of these necessary conditions does not hold well, the occurrence of a Deadlock
can be prevented.
1. Mutual Exclusion – not required for sharable resources; must hold for non sharable resources.
For example, a printer cannot be simultaneously shared by several processes.
2. 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.
Disadvantages
x Resource allocated maybe unused for a long period--Low resource utilization;
x More Waiting time for resources ---starvation possible
3. 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.
4. Circular Wait – impose a total ordering of all resource types, and require that each process
requests resources in an increasing order of enumeration (list).
Requires additional information about how the resources are to be requested by the processes.
Simplest and most useful model requires that each process declare the maximum number of
resources of each type that it may need.
A deadlock –avoidance algorithm dynamically checks the resource -allocation state to make sure
that a circular-wait condition never exists.
Resource-allocation state is defined by the number of available and allocated resources, and the
maximum demands of the resources
When a process requests an available resource, system must decide if immediate allocation leaves
the system in a safe state.
System is in safe state if there exists a safe sequence of all processes.
The two deadlock avoidance algorithms are:
1. Resource allocation graph for single instance of a resource type
2. Banker’s algorithm for multiple instances of a resource type.
♥ Available: It is a Vector of length defining the number of available resources of each type
. If available [j] = k, there are k instances of resource type Rj available.
♥ Max: It is an n x m matrix defines the maximum demand of each process for each resource type
. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj.
♥ Allocation: It is an n x m matrix defines the number of resources of each type currently allocated
to each process.
If Allocation[i,j] = k then Pi is currently allocated k instances of Rj.
Step4: If finish[i] == true for all i, then the system is in a safe state, otherwise unsafe.
Address Binding:
A program is normally saved on a disk as a binary executable file.
The program has to be loaded into memory and placed within a process to be executed.
Dynamic Loading: (2M-2015)
In dynamic loading, a program or routine is not loaded until it is called.
All routines are stored on the disk in a reloadable load format
Useful when large amounts of code are needed to handle infrequently occurring cases
Dynamic Linking:
The concept of dynamic linking is similar to dynamic loading except that linking is postponed until
execution time
Logical vs. Physical Address Space:
An address generated by the CPU is called logical address
The logical address is also known as virtual address
An address generated by a memory unit is referred to as a physical address
OVERLAYS: (5M-2014) (2M-2015)(2M-2011)(2M-2010)
♥ Overlays means replacement of a block of stored instruction or data with another
♥ Overlays are used to enable a process /programs to be larger than the amount of memory allocated
to it.
♥ The idea of overlays is to keep in memory only those instructions and data that are needed at any
given time.
♥ Needed when process is larger than amount of memory allocated to it.
♥ Implemented by user, no special support needed from operating system, programming design of
overlay structure is complex
Pass 1 70 KB
Pass 2 80 KB
Symbol table 20 KB
Common routines 30 KB
Advantages
Requires small amount of memory for working
No special support needed from operating system.,
Overlays are implemented by user,
Disadvantages
x Programming design of overlay structure is complex.
---------------------------------------------------------------------
SWAPPING: (2M-2011)
.
♥ A process can be swapped temporarily out of memory to a backing store, and then brought back into
memory for continued execution
♥ Backing store : – fast disk large enough to accommodate copies of all memory images for all users;
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
Advantages
Swapping can increase the degree of multiprogramming
It can be used to relocate and help external fragmentation
Disadvantages
x Swapping whole partitions is expensive.
x The context switch time is high
x Swapping a process with pending i/o operations is very complex
Fragmentation: (5M-2015)
Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too
small to satisfy any request.
2) PAGING: (2M-2011)
♥ Paging is a memory management scheme which permits the physical address of process to be non
contiguous.
♥ Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512
bytes and 8192 bytes).
♥ Divide logical memory into blocks of same size called pages.
♥ Keep track of all free frames.
♥ To run a program of size n pages, need to find n free frames and load program.
♥ Set up a page table to translate logical to physical addresses.
Example:
Advantages:
Paging supports time sharing system.
It avoids fragmentation resulting in better memory and processor utilization
It supports virtual memory
Compaction overhead are eliminated
Sharing of common code is possible in a paging system
Disadvantages:
x Paging sometimes suffer from the page breaks causing internal fragmentation, due to wastage of
memory in the last page allocated. On an average, half page per process is wasted.
x When number of pages are large, it is difficult to maintain the page table.
x Hardware cost is high.
x Paging increases the context switch time , slowing down the CPU.
♥ The percentage of times that a particular page number is found in the TLB is called hit ratio.
♥ A 80% hit ratio means that the desired page number in the TLB is found 80 percent of time
♥ Short for translation look-aside buffer, a table in the processor memory that contains information
about the pages in memory the processor has accessed recently.
3) Segmentation: (2M-2011)(6M-2010)
A program is a collection of segments. A segment is a logical unit such as:
main program,
procedure,
function,
method,
object,
local variables, global variables,
common block,
stack,
symbol table, arrays
Segmentation is a memory-management scheme that supports user view of memory
Segmentation Paging
-Program is divided in to variable sized ·Programs are divided in to fixed size pages.
segments.
-User is responsible for dividing the program in -Division is performed by the OS.
to segments.
-Segmentation is slower than paging. -Paging is faster than segmentation.
-Visible to user. -Invisible to user.
-Eliminates internal fragmentation. -Suffers from internal fragmentation.
-Suffers from external fragmentation. - No external fragmentation.
-Process or user segment number, offset to -Process or user page number, offset to
calculate absolute address. calculate absolute address.
demand paging: ( 7M-2015)(5M-2012)(5M-2010)
Demand paging is a type of swapping in which pages of data are not copied from disk to RAM until they
are needed. In contrast, some virtual memory systems use anticipatory paging, in which the operating
system attempts to anticipate which data will be needed next and copies it to RAM before it is actually
required.
Thus Demand Paging is bringing a page into memory only when it is needed.
Advantages:
Only fetch the pages of data that a program actually uses from the disk
If a program only needs to reference a fraction of its data during each timeslice of execution,
this can significantly reduce the amount of time spent copying data to and from the disk
Individual pages of a program’s data can be brought into the memory as needed, making the limit
on the maximum amount of data a program can reference the amount of space available on the
disk, not the amount of main memory
Outweigh the disadvantages for most applications
Demand paging the choice for most current workstation/PC operating systems
A page is a fixed length memory block used as a transferring unit between physical memory and an
external storage. A page fault occurs when a program accesses a page that has been mapped in address
space, but has not been loaded in the physical memory.
The memory manager is responsible for allocating primary memory to processes and for assisting the
programmer in loading and storing the contents of the primary memory.
Since primary memory can be space-multiplexed, the memory manager can allocate a portion of primary
memory to "each process" for its own use.
Available memory is called hole.
1) Sequential Access:
Information from the file is accessed in order, one record after the other. Compilers, multimedia
applications, sound files, etc. are the most common examples of programs using sequential access.
In case of a read operation, the record at the location pointed by the file pointer is read and the
file pointer is then advanced to the next record.
In case of write operation, the record is written to the end of the file and pointer is advanced to
end of new record.
2) Direct access:
Direct access method is also called related access. It is based on a disk model of a file, because
disks allow random access to any file block
In direct access method records can be read/write randomly without any order. In this model, the
file is viewed as a numbered sequence of blocks or records
The block number provided by the user to the operating system is a relative block number. A
relative block number is an index relative to the beginning of the file. Thus, the first relative block
of the file is 0, the next is 1 and so on.
The relative block number allows the operating system to decide where the file should be placed and
helps the user from accessing portions of the file system that may not be a part of the file.
3) Indexed Method:
This method involves the construction of an index for the file. The index contains pointers to the
various blocks.
To find a record in the file, the index must be searched first, and then use the pointer to access
the file directly and to find the desired record.
The primary index file would contain pointers to secondary index files which would then point to the
actual data items.
Disadvantages:-
x Not suitable for a large number of files and more than one user.
x Because of single directory files, files require unique file names.
x Difficult to remember names of all the files as the number of files increases.
x MS-DOS OS allows only 11 character file name where as UNIX allows 255 character.
2) Two-Level Directory:
Separate directory for each user is created(MFD-Master File Directory, UFD-User File Directory)
To create a file for a user, the operating system searches only that user’s UFD to check whether
another file of that name exists. To delete a file, the operating system searches for that file within
the UFD of that user. Therefore, it cannot delete another user’s file with the same name, by
mistake
Two-Level Directory Disadvantages:
x This structure isolates one user from another and thus forms disadvantage when the users want
to cooperate on some task and want to access one another’s files
x To access another’s file the path (user name and the path name) should be specified.
3) Tree-Structured Directories:
A tree is the most common directory structure
The tree has a root directory. Every file in the system has a unique path name.
A directory contains a set of files and subdirectories. A directory is treated like any other file
and all the directories have the same internal format.
Each user has a current directory that contains most of the files of current interest to the
user
When a file is to be accessed, the current directory is searched first. If the file is in another
directory then the user can specify the path or change the directory holding the required file as
the current directory.
Advantages:
Accessing a file that has been allocated contiguously is easy
Both sequential and direct access can be supported by contiguous allocation
Efficient usage of memory and CPU
Disadvantages:
x It is very difficult to find contiguous free blocks for a new file
x If a little space is allocated to the file, then the file cannot be extended
x If more space is allocated, memory is wasted small files
2) LINKED ALLOCATION:
Linked list solves all the problem of contiguous allocation
With linked allocation, each file is a linked list of disk blocks
The disk blocks may be scattered anywhere on the disk
The directory contains a pointer to the first and last blocks of the file
Each block contains a pointer to the next block
Advantages:
There is no need to declare the size of a file when that file is created
It never requires disk compaction
Disadvantages:
x It can be used effectively for only sequential access files and it does not support direct access.
x Extra space is required to store pointers
x There is no reliability
x It takes longer seek time
3) Indexed Allocation:
A modification of linked allocation where the disk block pointers for a file are all placed in an index
block
File indexes are stored in separate block and the entry for the file in the file allocation table
points to that block
Allocation may be on basis of either fixed size block or variable size block
Advantages:
Provides efficient random access
Indexed Allocation
Free space management: (5M-2014)(5M-2010)
Since disk space is limited, need to reuse the space from deleted files for new files, if possible.
To keep track of free disk space, the system maintains a free-space list.
The free-space list records all free disk blocks that are not being used.
To create a file, the free-space list is searched for the required amount of space, and allocated
that space to the new file.
This space is then removed from the free-space list.
When a file is deleted, its disk space is added to the free-space list.
1) Bit Vector
Frequently, the free-space list is implemented as a bit map or bit vector.
Each block is represented by 1 bit.
If the block is free, the bit is 1;
If the block is allocated, the bit is 0.
For example, consider a disk where blocks 2, 3, 4, 5, 8, 9, are free and the rest of the blocks are
allocated.
The free-space bit map would be 0011110011000…
The main advantage of this approach is its relative simplicity and its efficiency in finding the
first free block or consecutive free blocks on the disk.
But it takes more space to store the bitmap,it occupies large amount of main memory
2) Linked List:
Another approach to free-space management is to link together all the free disk blocks, keeping
a pointer to the first free block in a special location on the disk and caching it in memory.
This first block contains a pointer to the next free disk block, and so on.
3) Grouping:
A modification of the free-list approach is to store the addresses of n free blocks in the first
free block.
The first n-1 of these blocks are actually free. The last block contains the addresses of other n
free blocks, and so on.
The addresses of a large number of free blocks can now be found quickly, unlike the situation
when the standard linked-list approach is used.
4) Counting:
The address of the first n free block and the number of free contiguous blocks that follow the
first block.
Each entry in the free-space list then consists of a disk address and a count.
Although each entry requires more space than would a simple disk address, the overall list will be
shorter, as long as the count is generally greater than 1.
METHODS OF DATA RECOVERY IN FILE SYSTEMS: (5M-2011)
Files and directories are kept both in main memory and on disk
Care must be taken to ensure that system failure does not result in loss of data or in data
inconsistency.
Important methods to recover files from system failures are:
Consistency checking
Backup and Restore
1) Consistency Checking:
In case the system crashes before it writes all the modified blocks, the file system is left in an
inconsistent state.
A special program is run at reboot time to check for and correct disk inconsistencies.
The consistency-checker a system program such as fsck in Unix and chkdsk in MS DOS compares
the data in the directory structure with the data blocks in disk and tries to fix any
inconsistencies it finds.
The performance of a computer system depends on how fast a disk I/O requested is serviced.
For each I/O request, first, a head is selected. Then the head is moved over the destination track.
After that, the disk is rotated to position the desired sector under the head. Finally, the I/O
operation is performed.
The Different disk scheduling algorithms are:
First Come First Serve (FCFS) Scheduling
Shortest seek Time First(SSTF) Scheduling
SCAN Scheduling
Circular SCAN(CSCAN) Scheduling
LOOK Scheduling
Circular LOOK(C-LOOK) Scheduling
FCFS
2) SSTF Scheduling : [Shortest-Seek-time First] (5M-2012)
The shortest-seek-time-first selects the request with the minimum seek time from the current
head position. i.e all the requests close to the current head position is serviced first before moving
the head away to service other requests
Since seek time increases with the number of cylinders traversed by the head, SSTF chooses the
pending requests closest to the current head position
Example: Consider an example of a disk queue with requests for I/O to blocks on cylinders 98, 183,
37,122,14,124,65,67. If the disk head is initially at cylinder 53, calculate the head movement , average
waiting time.
Solution: The total head movement is
=(53 to 65) + (65 to 67) + (67 to 37) + (37 to 14) + (14 to 98 )+ (98 to 122) + (122 to 124) + (124 to
183)=12 +2+30 +23+84+24+2 +59= 236 cylinders
Average waiting time = 236/8 =32.37 cylinders
SSTF
3) SCAN SCHEDULING:
In the SCAN algorithm, the disk arm starts at one end of the disk, and moves toward the other end,
servicing requests as it reaches each cylinder until it gets to the other end of the disk
At the other end, the direction of head movement is reversed and servicing continues. The head
continuously scans back and forth across the disk
The SCAN algorithm is also called elevator algorithm since the disk arm just like the elevator in a
building, first services all the requests going up, and then reversing to service the requests in the
other direction.
Example: Consider an example of a disk queue with requests for I/O to blocks on cylinders 98, 183,
37,122,14,124,65,67. If the disk head is initially at cylinder 53, and direction is towards 0, calculate the
head movement , average waiting time
Solution: From the current position 53, the head will service 37 and 14. At cylinder 0, the arm will
reverse and will move towards the other end of the disks, servicing the requests 65, 67, 98,122,124 and
183.
Total Head Movement = (53 to 37) + (37 to 14) + (14 to 0) + (0 to 65) + (65 to 67 )+ (67 to 98) + (98
to 122) + (122 to 124) + (124 to 183)=16 +23+14+65+2+31+24+2+59=236 cylinders
The average waiting time= 236/8= 32.37 cylinders.
SCAN SCHEDULING
4) Circular SCAN(CSCAN) Scheduling
Circular C-Scan scheduling is a variant of SCAN designed to provide a more uniform wait time than
SCAN
It overcomes the drawback of SCAN scheduling where some requests must wait for longer time
compared to others which are serviced immediately
In C-SCAN the head moves from one end of the disk to the other servicing requests as it goes.
When the head reaches the other end, however it immediately returns to the beginning of the disk,
without servicing any requests on the return trip
C-SCAN treats the cylinders as a circular list that wraps around from the last cylinder to the first
one.
Example: Consider an example of a disk queue with requests for I/O to blocks on cylinders 98, 183,
37,122,14,124,65,67. If the disk head is initially at cylinder 53, and direction is towards outside,
calculate the head movement, average waiting time
Solution: From the current position 53, the head will service 65, 67, 98, 122, 124, 183, 199. Then head
returns to the beginning of the disk 0, and will service 14, 37.
Total Head Movement = (53 to 65) + (65 to 67) + (67 to 98) + (98 to 122) + (122 to 124 )+ (124 to
183) + (183 to 199) + (199 to 0) + (0 to 14) + (14 to 37) =12
+2+31+24+2+59+16+199+14+23=382 cylinders
The average waiting time=383/8= 47.75 cylinders.
C-SCAN
5) LOOK SCHEDULING:
Both SCAN and C-SCAN scheduling algorithm move the disk arm across the full width of the disk
A variant of SCAN and C-SCAN is LOOK and C-LOOK
In this method, the arm only goes as far as the last request in each direction. It then reverses its
direction immediately, without reaching the end of the disk.
LOOK scheduling as in SCAN, requests are served when the head moves in both directions.
Example: Consider an example of a disk queue with requests for I/O to blocks on cylinders 98, 183,
37,122,14,124,65,67. If the disk head is initially at cylinder 53, and direction is towards outside,
calculate the head movement, average waiting time
Solution: From the current position 53, the head will service 65, 67, 98, 122, 124, 183. Then head
reverses its direction immediately, and will service 37 and 14.
Total Head Movement = (53 to 65) + (65 to 67) + (67 to 98) + (98 to 122) + (122 to 124 )+ (124 to
183) + (183 to 37) + (37 to 14)=12 +2+31+24+2+59+146+23=299 cylinders
The average waiting time= 299/8= 37.375 cylinders.
6) C-LOOK SCHEDULING
This is a variation of LOOK in which the head starts at the innermost cylinder requests and
moves outward fulfilling requests until it reaches the last request. Then it moves back to the
innermost request again without servicing any request in the reverse direction.
Example: Consider an example of a disk queue with requests for I/O to blocks on cylinders 98, 183,
37,122,14,124,65,67. If the disk head is initially at cylinder 53, and direction is towards outside,
calculate the head movement, average waiting time
Solution: From the current position 53, the head will service 65, 67, 98, 122, 124, 183. Then head
reverses its direction immediately, and will service 14 and 37.
Total Head Movement = (53 to 65) + (65 to 67) + (67 to 98) + (98 to 122) + (122 to 124 ) + (124 to
183) + (183 to 14) + (14 to 37) =12 +2+31+24+2+59+169+23=322 cylinders
The average waiting time=322/8= 40.25 cylinders.
C-LOOK
Disk formatting (2M-2015)
Disk formatting is the process of preparing a data storage device such as a hard disk drive,
solid-state drive, floppy disk or USB flash drive for initial use.
Low-level formatting or Physical formatting involves dividing disk into sectors so that the disk
controller can read and write.
Low-level formatting fills the disk with a special data structure for each sector that consists of
a header, a data area and a trailer. The header and trailer contain information used by the
disk controller, such as sector number and an error-correcting code(ECC)
♥ Virtual Memory is a technique that allows the execution of processes that may not be completely in
memory. One major advantage of this scheme is that programs can be larger than physical memory.
Further, virtual memory abstracts main memory into an extremely large, uniform array of storage,
separating logical memory as viewed by the user from physical memory. This technique frees
programmers from the concerns of memory-storage limitations.
♥ Virtual memory is a memory management technique that allows the execution of processes, which
may not be completely in memory.
♥ The main advantage of this scheme is that user programs can be larger than the physical memory.
♥ The operating system keeps only those parts of the program in memory, which are required during
execution.
♥ The rest of it is kept on the disk.
♥ In fact Virtual memory allows execution of partially loaded processes, allowing user programs to be
larger than the physical memory.
ENCRYPTION: (2M-2015)(2M-2011)