OOPERATING SYSTEM 4TH SEMESTER
OOPERATING SYSTEM 4TH SEMESTER
1. Process Management
The process management refers to the assignment of processor to different tasks
being performed by the computer system. The process management schedules the
various processes of a system for execution.
The operating system is responsible for the following activities in connection with
process management:
1. Creating and deleting both user and system processes.
2. Suspending and resuming processes.
3. Providing mechanisms for process synchronization such as semaphores.
4. Providing mechanism for process communication(i.e. communication between
different processes in a system)
5. Providing mechanisms for deadlock handling. Deadlock is a condition in which the
number of processes waits infinitely for some shared resource.
2. Memory Management
The operating system manages the Primary Memory or Main Memory. Main memory
is made up of a large array of bytes or words where each byte or word is assigned a
certain address.
Main memory is a fast storage and it can be accessed directly by the CPU. For a
program to be executed, it should be first loaded in the main memory.
An Operating System performs the following activities for memory management:
1. It keeps tracks of primary memory, i.e., which bytes of memory are used by which
user program.
2. Deciding which processes are to be loaded into memory when memory space
becomes available
3. Allocating and deallocating memory spaces as needed
In multi programming, the OS decides the order in which process are granted access
to memory, and for how long.
4. File Management
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions.
An Operating System does the following activities for file management −
Keeps track of information, location, uses, status etc. The collective facilities are
often known as file system.
Decides who gets the resources.
Allocates the resources.
De-allocates the resources.
5. I/O Management
I/O management refers to the coordination and assignment of the different input and
output devices to the various programs that are being executed.
Thus, an OS is responsible for managing various I/O devices, such as keyboard,
mouse, printer and monitor.
The I/O sub system consists of following components:
1. A memory management component that includes buffering, caching and spooling.
2. A general device-driver interface.
3. Drivers for specific hardware devices.
The operating system performs following function related to I/O management
1. Issuing commands to various input and output devices.
2. Capturing interrupt such as hardware failure.
3. Handling errors that appear in reading and writing process of devices.
4. Security
Security deals with protecting the various resources and information of a computer
system against destruction and unauthorized access.
A total approach to computer security involves both external and internal security.
External security deals with securing the computer system against external factors
such as fires, floods, earthquakes, stolen disks/tapes, leaking out of stored information
by a person who has access to the information.
Internal security deals with users’ authentication, access control and cryptography.
7. Networking
Networking is used for exchanging information among different computer that are
distributed across various locations.
Distributed systems consist of multiple processor and each processors has its own
memory and clock.
The various processors communicate using communication links, such as telephone
lines or buses.
The processors in distributed system vary is size and functions. They may include
small microprocessors, workstation, minicomputers and large general purpose
computer systems.
Thus, a distributed system enables us to share the various resources of the network.
This results in computation speedup, increased functionality, increased data
availability and better reliability.
8. Command Interpretation
The command interpreter is the basic interface between the computer and the user.
Command interpreter provides a set of commands using which the user can give
instruction to the computer for getting some job done by it.
The various commands supported by command interpretation module are known as
system calls.
When a user gives instructions to the computer by using these system calls, the
command interpreter takes care of interpreting these commands and directing the
system resources to handle the requests.
There are two different user interfaces supported by various operating systems:
1. Command line interface
2. Graphical user interface
Command line Interface (CLI):- It is the textual user interface in which user gives
instruction to computer by typing the commands.
Graphical user interface (GUI):- GUI provides the user a screen full of graphical
icons or menus and allows the user to make a rapid selection from the displayed icons
or menus to give instruction to computer.
Operating system as a resource manager
A computer system usually has many hardware and software resources such as
processor, memory, disks, printers, I/O devices etc. The operating system acts as a
manager of these resources.
The operating system is responsible for controlling and allocating various hardware
and software resources to different users in an optimal and efficient manner.
The task of resources management becomes essential in multi user operating systems
where different users compete for the same resources.
As a resource manager, an operating system keeps track of:
1. Who is using which resources
2. Granting resource requests
3. Accounting resource usage
4. Mediating conflicting requests from different programs and users.
Operating system manages resources in two ways:
1. Time Multiplexing: – It defines the sharing of resources on the basis of fixed time
slices. For example, the operating system allocates the resources, such as CPU to
program A for a fixed time slice. After that time slice is over, the CPU is allocated to
another program B and so on.
2. Space Multiplexing:- It defines the concurrent sharing of resources among different
programs. For example, sharing of hard disk and main memory is space multiplexing.
Structures of Operating Systems
Operating system can be implemented with the help of various structures. The structure of the OS
depends mainly on how the various common components of the operating system are
interconnected and melded into the kernel. Depending on this we have following structures of the
operating system:
Simple structure:
Such operating systems do not have well defined structure and are small, simple and limited
systems. The interfaces and levels of functionality are not well separated. MS-DOS is an example
of such operating system. In MS-DOS application programs are able to access the basic I/O
routines. These types of operating system cause the entire system to crash if one of the user
programs fails.
Diagram of the structure of MS-DOS is shown below.
Layered structure:
An OS can be broken into pieces and retain much more control on system. In this structure the
OS is broken into number of layers (levels). The bottom layer (layer 0) is the hardware and the
topmost layer (layer N) is the user interface. These layers are so designed that each layer uses the
functions of the lower level layers only. This simplifies the debugging process as if lower level
layers are debugged and an error occurs during debugging then the error must be on that layer
only as the lower level layers have already been debugged.
The main disadvantage of this structure is that at each layer, the data needs to be modified and
passed on which adds overhead to the system. Moreover careful planning of the layers is
necessary as a layer can use only lower level layers. UNIX is an example of this structure.
Micro-kernel:
This structure designs the operating system by removing all non-essential components from the
kernel and implementing them as system and user programs. This result in a smaller kernel called
the micro-kernel.
Advantages of this structure are that all new services need to be added to user space and does not
require the kernel to be modified. Thus it is more secure and reliable as if a service fails then rest
of the operating system remains untouched. Mac OS is an example of this type of OS.
User View
The user view depends on the system interface that is used by the users. The different types of
user view experiences can be explained as follows −
If the user is using a personal computer, the operating system is largely designed to
make the interaction easy. Some attention is also paid to the performance of the
system, but there is no need for the operating system to worry about resource
utilization. This is because the personal computer uses all the resources available and
there is no sharing.
If the user is using a system connected to a mainframe or a minicomputer, the
operating system is largely concerned with resource utilization. This is because there
may be multiple terminals connected to the mainframe and the operating system
makes sure that all the resources such as CPU, memory, I/O devices etc. are divided
uniformly between them.
If the user is sitting on a workstation connected to other workstations through
networks, then the operating system needs to focus on both individual usage of
resources and sharing though the network. This happens because the workstation
exclusively uses its own resources but it also needs to share files etc. with other
workstations across the network.
If the user is using a handheld computer such as a mobile, then the operating system
handles the usability of the device including a few remote operations. The battery
level of the device is also taken into account.
There are some devices that contain very less or no users view because there is no interaction
with the users. Examples are embedded computers in home devices, automobiles etc.
System View
According to the computer system, the operating system is the bridge between applications and
hardware. It is most intimate with the hardware and is used to control it as required.
The different types of system view for operating system can be explained as follows:
The system views the operating system as a resource allocator. There are many
resources such as CPU time, memory space, file storage space, I/O devices etc. that
are required by processes for execution. It is the duty of the operating system to
allocate these resources judiciously to the processes so that the computer system can
run as smoothly as possible.
The operating system can also work as a control program. It manages all the
processes and I/O devices so that the computer system works smoothly and there are
no errors. It makes sure that the I/O devices work in a proper manner without creating
problems.
Operating systems can also be viewed as a way to make using hardware easier.
Computers were required to easily solve user problems. However it is not easy to
work directly with the computer hardware. So, operating systems were developed to
easily communicate with the hardware.
An operating system can also be considered as a program running at all times in the
background of a computer system (known as the kernel) and handling all the
application programs. This is the definition of the operating system that is generally
followed.
Background Processing
Multitasking operating system creates the better environment to execute the background
programs. These background programs are not transparent for normal users, but these
programs help to run other programs smoothly such as firewall, antivirus software, and more.
Good Reliability
Multitasking operating system provides the several flexibilities for multiple users, and they
are more satisfied to them. On which, every users can operate single or multiple programs
with smoothly.
1. Both of these concepts are for single CPU. Both of these concepts are for single CPU.
2. Concept of Context Switching is used. Concept of Context Switching and Time Sharing is used.
Multi-programming increases CPU utilization In multi-tasking also increases CPU utilization, it also
4.
by organising jobs . increases responsiveness.
The idea is to reduce the CPU idle time for as The idea is to further extend the CPU Utilization concept by
5.
long as possible. increasing responsiveness Time Sharing.
6. 6. Multiprocessing System
Multiprocessor system is the system that contains two or more processors or CPU’s and
has ability to simultaneously execute several programs. Hence the name multi-processor.
In such a system, multiple processors share the clock, bus, memory and peripheral
devices.
A multiprocessor system is also known as parallel system.
In such a system, instructions from different and independent programs can be
processed at the same instant of time by different CPU’s.
In this system, the CPU’s simultaneously execute different instructions from the same
program.
Types of Multiprocessors
There are mainly two types of multiprocessors i.e. symmetric and asymmetric
multiprocessors. Details about them are as follows −
Symmetric Multiprocessors
In these types of systems, each processor contains a similar copy of the operating system and
they all communicate with each other. All the processors are in a peer to peer relationship i.e.
no master – slave relationship exists between them.
An example of the symmetric multiprocessing system is the Encore version of UNIX for the
Multimax Computer.
Asymmetric Multiprocessors
In asymmetric systems, each processor is given a predefined task. There is a master processor
that gives instruction to all the other processors. Asymmetric multiprocessor system contains
a master slave relationship.
Asymmetric multiprocessor was the only type of multiprocessor available before symmetric
multiprocessors were created. Now also, this is the cheaper option.
Advantages of Multiprocessor Systems
There are multiple advantages to multiprocessor systems. Some of these are −
More reliable Systems
In a multiprocessor system, even if one processor fails, the system will not halt. This ability
to continue working despite hardware failure is known as graceful degradation. For example:
If there are 5 processors in a multiprocessor system and one of them fails, then also 4
processors are still working. So the system only becomes slower and does not ground to a
halt.
Enhanced Throughput
If multiple processors are working in tandem, then the throughput of the system increases i.e.
number of processes getting executed per unit of time increase. If there are N processors then
the throughput increases by an amount just under N.
More Economic Systems
Multiprocessor systems are cheaper than single processor systems in the long run because
they share the data storage, peripheral devices, power supplies etc. If there are multiple
processes that share data, it is better to schedule them on multiprocessor systems with shared
data than have different computer systems with multiple copies of the data.
Disadvantages of Multiprocessor Systems
There are some disadvantages as well to multiprocessor systems. Some of these are:
Increased Expense
Even though multiprocessor systems are cheaper in the long run than using multiple
computer systems, still they are quite expensive. It is much cheaper to buy a simple single
processor system than a multiprocessor system.
Complicated Operating System Required
There are multiple processors in a multiprocessor system that share peripherals, memory etc.
So, it is much more complicated to schedule processes and impart resources to processes.
than in single processor systems. Hence, a more complex and complicated operating system
is required in multiprocessor systems.
Large Main Memory Required
All the processors in the multiprocessor system share the memory. So a much larger pool of
memory is required as compared to single processor systems.
Difference between Multiprocessing and multiprogramming
S.No. Multiprocessing Multiprogramming
The availability of more than one processor per system The concurrent application of more than one
1. that can execute several set of instructions in parallel is program in the main memory is known as
known as multiprocessing. multiprogramming.
2. The number of CPU is more than one. The number of CPU is one.
3. It takes less time for job processing. It takes more time to process the jobs.
4. In this, more than one process can be executed at a time. In this, one process can be executed at a time.
5. It is economical. It is economical.
6. The number of users is can be one or more than one. The number of users is one at a time.
Advantages of RTOS:
Maximum Consumption:Maximum utilization of devices and system, thus more output
from all the resources
Task Shifting:The time assigned for shifting tasks in these systems are very less. For
example, in older systems, it takes about 10 microseconds in shifting one task to another,
and in the latest systems, it takes 3 microseconds.
Focus on Application:Focus on running applications and less importance to applications
which are in the queue.
Real-timeoperating system in the embedded system: Since the size of programs are
small, RTOS can also be used in embedded systems like in transport and others.
Error Free:These types of systems are error-free.
Memory Allocation:Memory allocation is best managed in these types of systems.
Disadvantages of RTOS:
Limited Tasks:Very few tasks run at the same time and their concentration is very less on
few applications to avoid errors.
Use heavy system resources:Sometimes the system resources are not so good and they
are expensive as well.
Complex Algorithms:The algorithms are very complex and difficult for the designer to
write on.
Device driver and interrupt signals:It needs specific device drivers and interrupts signals
to respond earliest to interrupts.
Thread Priority:It is not good to set thread priority as these systems are very less prone
to switching tasks.
Examples of Real-Time Operating Systems are: Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic control systems, etc.
Difference between Hard real time and Soft real time system :
HARD REAL TIME SYSTEM SOFT REAL TIME SYSTEM
In this system response time is in millisecond. In this system response time are higher.
Peak load performance should be predictable. In soft real time system, peak load can be tolerated.
A hard real time system is very restrictive. A Soft real time system is less restrictive.
In case of an error in a hard real time system, the In case of an soft real time system, computation is rolled back
computation is rolled back. to previously established a checkpoint.
Satellite launch, Railway signaling system etc. DVD player, telephone switches, electronic games etc.
In time sharing operating system, quick response While in real time operating system, computation tasks
1.
is emphasized for a request. are emphasized before its nominative point.
In this OS, computer resources are shared to the But in this OS, computer resources are not shared to the
4.
external. external.
It deals with more than processes or applications Whereas it deals with only one process or application at
5.
simultaneously. a time.
In this OS, the response is provided to the user While in real time OS, the response is provided to the
6.
within a second. user within time constraint.
Device Queue
Device queue contains all those processes that are waiting for a particular I/O device.
Each device has its own device queue.
Types of schedulers
Scheduler
A scheduler is an operating system module that selects the next job or process to be
admitted into the system.
Thus, a scheduler selects one of the processes from among the processes in the
memory that are ready to execute and allocates CPU to it.
Concept of Thread
A is a single sequential flow of execution of the tasks of a process.
A thread is a lightweight process and the smallest unit of CPU utilization. Thus a
thread is like a little miniprocess.
Each thread has a thread id, a program counter, a register set and a stack.
A thread undergoes different states such as new, ready, running, waiting and
terminated similar to that of a process.
However, a thread is not a program as it cannot run on its own. It runs within
program.
Why Multithreading?
A thread is also known as lightweight process. The idea is to achieve parallelism by dividing a
process into multiple threads. For example, in a browser, multiple tabs can be different threads.
MS Word uses multiple threads: one thread to format the text, another thread to process inputs,
etc.
Types of Threads:
1. User Level thread (ULT)
Is implemented in the user level library, they are not created using the system calls.
Thread switching does not need to call OS and to cause interrupt to Kernel. Kernel
doesn’t know about the user level thread and manages them as if they were single-
threaded processes.
Advantages of ULT
Can be implemented on an OS that doesn’t support multithreading.
Simple representation since thread has only program counter, register set, stack space.
Simple to create since no intervention of kernel.
Thread switching is fast since no OS calls need to be made.
Disadvantages of ULT –
No or less co-ordination among the threads and Kernel.
If one thread causes a page fault, the entire process blocks.
CPU Scheduling
CPU Scheduling
Scheduling is a fundamental operating system function.
Scheduling refers to set of policies and mechanisms built into the operating system
that governs the order in which the work to be done by a computer system is
completed.
CPU scheduling is the basis of multiprogrammed operating system.
Why do we need Scheduling?
In Multiprogramming, if the long term scheduler picks more I/O bound processes
then most of the time, the CPU remains idol. The task of Operating system is to
optimize the utilization of resources.
If most of the running processes change their state from running to waiting then
there may always be a possibility of deadlock in the system. Hence to reduce this
overhead, the OS needs to schedule the jobs to get the optimal utilization of CPU
and to avoid the possibility to deadlock.
CPU Scheduling: Dispatcher
Another component involved in the CPU scheduling function is the Dispatcher. The dispatcher is
the module that gives control of the CPU to the process selected by the short-term scheduler.
This function involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that program from
where it left last time.
The dispatcher should be as fast as possible, given that it is invoked during every process switch.
The time taken by the dispatcher to stop one process and start another process is known as
the Dispatch Latency. Dispatch Latency can be explained using the below figure:
The durations of CPU bursts have been measured extensively. They tend to have a
frequency curve similar to that shown in Fig. 11.
Some processes, such as the one in, spend most of their time computing (CPU-
bound), while others, such as the one in, spend most of their time waiting for I/O
(I/O-bound).
Having some CPU-bound processes and some I/O-bound processes in memory
together is a better idea than first loading and running all the CPU-bound jobs and
then when they are finished loading and running all the I/O-bound jobs (a careful
mix of processes).
0 0 2 2 2 0
1 1 6 8 7 1
2 2 4 12 8 4
3 3 9 21 18 9
4 4 12 33 29 17
1 1 7 8 7 0
2 3 3 13 10 7
3 6 2 10 4 2
4 7 10 31 24 14
5 9 8 21 12 4
Advantages
1. It can be actually implementable in the system because it is not depending on the burst
time.
2. It doesn’t suffer from the problem of starvation or convoy effect.
3. All the jobs get a fare allocation of CPU.
Disadvantages
1. The higher the time quantum, the higher the response time in the system.
2. The lower the time quantum, the higher the context switching overhead in the system.
3. Deciding a perfect time quantum is really a very difficult task in the system.
RR Scheduling Example
In the following example, there are six processes named as P1, P2, P3, P4, P5 and P6. Their
arrival time and burst time are given below in the table. The time quantum of the system is 4
units.
Process ID Arrival Time Burst Time
1 0 5
2 1 6
3 2 3
4 3 1
5 4 5
6 6 4
According to the algorithm, we have to maintain the ready queue and the Gantt chart. The
structure of both the data structures will be changed after every scheduling.
Ready Queue:
Initially, at time 0, process P1 arrives which will be scheduled for the time slice 4 units.
Hence in the ready queue, there will be only one process P1 at starting with CPU burst time 5
units.
P1
GANTT chart
The P1 will be executed for 4 units first.
Ready Queue
Meanwhile the execution of P1, four more processes P2, P3, P4 and P5 arrives in the ready
queue. P1 has not completed yet, it needs another 1 unit of time hence it will also be added
back to the ready queue.
P2 P3 P4 P5 P1
6 3 1 5 1
GANTT chart
After P1, P2 will be executed for 4 units of time which is shown in the Gantt chart.
Ready Queue
During the execution of P2, one more process P6 is arrived in the ready queue. Since P2 has
not completed yet hence, P2 will also be added back to the ready queue with the remaining
burst time 2 units.
P3 P4 P5 P1 P6 P2
3 1 5 1 4 2
GANTT chart
After P1 and P2, P3 will get executed for 3 units of time since its CPU burst time is only 3
seconds.
Ready Queue
Since P3 has been completed, hence it will be terminated and not be added to the ready
queue. The next process will be executed is P4.
P4 P5 P1 P6 P2
1 5 1 4 2
GANTT chart
After, P1, P2 and P3, P4 will get executed. Its burst time is only 1 unit which is lesser then
the time quantum hence it will be completed.
Ready Queue
The next process in the ready queue is P5 with 5 units of burst time. Since P4 is completed
hence it will not be added back to the queue.
P5 P1 P6 P2
5 1 4 2
GANTT chart
P5 will be executed for the whole time slice because it requires 5 units of burst time which is
higher than the time slice.
Ready Queue
P5 has not been completed yet; it will be added back to the queue with the remaining burst
time of 1 unit.
P1 P6 P2 P5
1 4 2 1
GANTT Chart
The process P1 will be given the next turn to complete its execution. Since it only requires 1
unit of burst time hence it will be completed.
Ready Queue
P1 is completed and will not be added back to the ready queue. The next process P6 requires
only 4 units of burst time and it will be executed next.
P6 P2 P5
4 2 1
GANTT chart
P6 will be executed for 4 units of time till completion.
Ready Queue
Since P6 is completed, hence it will not be added again to the queue. There are only two
processes present in the ready queue. The Next process P2 requires only 2 units of time.
P2 P5
2 1
GANTT Chart
P2 will get executed again, since it only requires only 2 units of time hence this will be
completed.
Ready Queue
Now, the only available process in the queue is P5 which requires 1 unit of burst time. Since
the time slice is of 4 units hence it will be completed in the next burst.
P5
GANTT chart
P5 will get executed till completion.
The completion time, Turnaround time and waiting time will be calculated as shown in the
table below.
As, we know,
1. Turn Around Time= Completion Time – Arrival Time
2. Waiting Time= Turn Around Time – Burst Time
Process ID Arrival Time Burst Time Completion Time Turn Around Time Waiting Time
1 0 5 17 17 12
2 1 6 23 22 16
3 2 3 11 9 6
4 3 1 12 9 8
5 4 5 24 20 15
6 6 4 21 15 11
All three different type of processes have there own queue. Each queue have its own
Scheduling algorithm. For example, queue 1 and queue 2 uses Round Robin while queue 3
can use FCFS to schedule there processes.
Scheduling among the queues : What will happen if all the queues have some processes?
Which process should get the cpu? To determine this Scheduling among the queues is
necessary. There are two ways to do so –
1. Fixed priority preemptive scheduling method –Each queue has absolute priority over
lower priority queue. Let us consider following priority order queue 1 > queue 2 > queue
3.According to this algorithm no process in the batch queue(queue 3) can run unless
queue 1 and 2 are empty. If any batch process (queue 3) is running and any system
(queue 1) or Interactive process(queue 2) entered the ready queue the batch process is
preempted.
2. Time slicing– In this method each queue gets certain portion of CPU time and can use it
to schedule its own processes.For instance, queue 1 takes 50 percent of CPU time queue
2 takes 30 percent and queue 3 gets 20 percent of CPU time.
Example Problem :
Consider below table of four processes under Multilevel queue scheduling.Queue number
denotes the queue of the process.
Priority of queue 1 is greater than queue 2. queue 1 uses Round Robin (Time Quantum = 2)
and queue 2 uses FCFS.
At starting both queues have process so process in queue 1 (P1, P2) runs first (because of
higher priority) in the round robin fashion and completes after 7 units then process in queue 2
(P3) starts running (as there is no process in queue 1) but while it is running P4 comes in
queue 1 and interrupts P3 and start running for 5 second and after its completion P3 takes the
CPU and completes its execution.
Advantages:
The processes are permanently assigned to the queue, so it has advantage of low
scheduling overhead.
Disadvantages:
Some processes may starve for CPU if some higher priority queues are never becoming
empty.
It is inflexible in nature.
UNIT-II
: Memory Management
Memory Management: Introduction
A computer uses two types of storage: Main memory and secondary memory.
Main memory temporarily stores data and instructions to be executed by the
computer.
As main memory is usually too small to accommodate all the data & programs, the
information is stored in various secondary storage devices such as magnetic disks
and magnetic tapes in the form of files.
The part of operating system that manages is called the memory manager.
The memory manger performs the following function:
1. To keep the track of which parts of memory are in use and which are free.
2. To allocate memory space to processes when they need and to deallocate it when
they are done.
To manage swapping between main memory and disk when main memory is not big
enough to hold all the processes.
1. To protect various processes so that they do not interface with each memory is not
big enough to hold all the processes.
2. To enable sharing of memory space between processes whenever required.
3. To make the addressing of memory space as transparent as possible from the
programmers.
In order to implement these functions memory manager uses variety of memory
management schemes
Contiguous, Real memory management system
Single contiguous memory management system
Fixed partitioned memory management system
Variable partitioned memory management system
Non-Contiguous, real memory management system
Paged memory management system
Segmented memory management system
Combined memory management system
Non—contiguous ,virtual memory management system
Virtual memory paging
Virtual memory segmentation
Address binding
The Association of program instruction and data to the actual physical memory locations is called
the Address Binding. Let’s consider the following example given below for better understanding.
Consider a program P1 has the set of instruction such that I1, I2, I3, I4, and program counter
value is 10, 20, 30, 40 respectively.
Program
P1I1 –> 10
I2 –> 20
I3 –> 30
I4 –> 40
Program Counter = 10, 20, 30, 40
The figure depicts a process image. The process image is occupying a continuous region of main
memory. The operating system will need to know many things including the location of process
control information, the execution stack, and the code entry. Within a program, there are memory
references in various instructions and these are called logical addresses.
After loading of the program into main memory, the processor and the operating system must be
able to translate logical addresses into physical addresses. Branch instructions contain the address
of the next instruction to be executed. Data reference instructions contain the address of byte or
word of data referenced.
(1) Static Relocation
The first basic method of relocation is static relocation. Static relocation is performed before or
during the loading of the program into memory, by a relocating linker/ loader.
In systems with static relocation, a swapped-out process must either be swapped back into the
same partition from which it was evicted.
Software relocation must be repeated whenever the process is to be loaded into a different
partition.
Systems with static relocation are practically restricted to supporting only static binding of
processes to partitions.
This method is the slow process because it involves software translation. It is used only once
before the initial loading of the program.
What happens exactly in this approach is that here operating system manages the memory address
of a process to reflect its starting position in the memory.
Once a process is assigned a starting address in memory it executes within the space it has been
allocate
(2) Dynamic Relocation
Another method of relocation is dynamic relocation. In it mapping from the virtual address space
to the physical address space is performed at run-time.
This runtime mapping from virtual address to physical address is performed by a hardware device
known as memory management unit.
When the program is compiled or when a process is executed by CPU will generate the logical
address. Put this address as LA and this logical address can never be less than zero, it has to be
zero or more.
So whenever the CPU generates the logical address, you add this logical address with the base
register (relocation register) content and that gives you the physical address in the main memory
where the instruction of that data will be found.
2.Protection –There is always a danger when we have multiple programs at the same
time as one program may write to the address space of another program. So every
process must be protected against unwanted interference when other process tries
to write in a process whether accidental or incidental. Between relocation and
protection requirement a trade-off occurs as the satisfaction of relocation
requirement increases the difficulty of satisfying the protection
requirement.Prediction of the location of a program in main memory is not possible,
that’s why it is impossible to check the absolute address at compile time to assure
protection. Most of the programming language allows the dynamic calculation of
address at run time. The memory protection requirement must be satisfied by the
processor rather than the operating system because the operating system can hardly
control a process when it occupies the processor. Thus it is possible to check the
validity of memory references.
3. Sharing –A protection mechanism must have to allow several processes to access the
same portion of main memory. Allowing each processes access to the same copy of
the program rather than have their own separate copy has an advantage.For
example, multiple processes may use the same system file and it is natural to load
one copy of the file in main memory and let it shared by those processes. It is the
task of Memory management to allow controlled access to the shared areas of
memory without compromising the protection. Mechanisms are used to support
relocation supported sharing capabilities.
Loading the entire program into the main memory Loading the program into the main
before start of the program execution is called as static memory on demand is called as dynamic
loading. loading.
Statically linked program takes constant load time every Dynamic linking is performed at run time
time it is loaded into the memory for execution. by the operating system.
If the static loading is used then accordingly static If the dynamic loading is used then
linking is applied. accordingly dynamic linking is applied.
Linking
Linking is performed at both compile time, when the source code is translated into machine code
and load time, when the program is loaded into memory by the loader. Linking is performed at
the last step in compiling a program.
Source code -> compiler -> Assembler -> Object code -> Linker -> Executable file ->
Loader
Linking is of two types:
1. Static Linking –
It is performed during the compilation of source program. Linking is performed
before execution in static linking. It takes collection of reloadable object file and
command-line argument and generate fully linked object file that can be loaded and
run.
Static linkers perform two major tasks:
Symbol resolution –It associates each symbol reference with exactly one symbol
definition .Every symbol have predefined task.
Relocation –It relocate code and data section and modify symbol references to the
relocated memory location.
2. Dynamic linking
Dynamic linking is performed during the run time. This linking is accomplished by
placing the name of a shareable library in the executable image. There is more
chances of error and failure chances. It require less memory space as multiple
program can share a single copy of the library.
Here we can perform code sharing. it means we are using a same object a number of
times in the program. Instead of linking same object again and again into the library,
each module share information of a object with other module having same object.
The shared library needed in the linking is stored in virtual memory to save RAM. In
this linking we can also relocate the code for the smooth running of code but all the
code is not relocatable.It fixes the address at run time.
Paging
In Operating Systems, Paging is a storage mechanism used to retrieve processes from the
secondary storage into the main memory in the form of pages.
The main idea behind the paging is to divide each process in the form of pages. The main
memory will also be divided in the form of frames.
One page of the process is to be stored in one of the frames of the memory. The pages can be
stored at the different locations of the memory but the priority is always to find the contiguous
frames or holes.
Pages of the process are brought into the main memory only when they are required otherwise
they reside in the secondary storage.
Different operating system defines different frame sizes. The sizes of each frame must be equal.
Considering the fact that the pages are mapped to the frames in Paging, page size needs to be as
same as frame size.
Let us consider the main memory size 16 Kb and Frame size is 1 KB therefore the main memory
will be divided into the collection of 16 frames of 1 KB each.
There are 4 processes in the system that is P1, P2, P3 and P4 of 4 KB each. Each process is
divided into pages of 1 KB each so that one page can be stored in one frame.
Initially, all the frames are empty therefore pages of the processes will get stored in the
contiguous way.
Frames, pages and the mapping between the two is shown in the image below.
Advantages of Segmentation
1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
4. It is easier to relocate segments than entire address space.
5. The segment table is of lesser size as compare to the page table in paging.
Disadvantages
1. It can have external fragmentation.
2. It is difficult to allocate contiguous memory to variable sized partition.
3. Costly memory management algorithms.
Difference between paging and segmentation
S.NO Paging Segmentation
In paging, program is divided into fixed or In segmentation, program is divided into variable size
1.
mounted size pages. sections.
3. Page size is determined by hardware. Here, the section size is given by the user.
5. Paging could result in internal fragmentation. Segmentation could result in external fragmentation.
In paging, logical address is split into page Here, logical address is split into section number and section
6.
number and page offset. offset.
S.NO Paging Segmentation
Paging comprises a page table which encloses While segmentation also comprises the segment table which
7.
the base address of every page. encloses segment number and segment offset.
In paging, operating system must maintain a In segmentation, operating system maintain a list of holes in
9.
free frame list. main memory.
In paging, processor needs page number, In segmentation, processor uses segment number, offset to
11.
offset to calculate absolute address. calculate full address.
Virtual Memory
A computer can address more memory than the amount physically installed on the system. This
extra memory is actually called virtual memory and it is a section of a hard disk that’s set up to
emulate the computer’s RAM.
The main visible advantage of this scheme is that programs can be larger than physical memory.
Virtual memory serves two purposes. First, it allows us to extend the use of physical memory by
using disk. Second, it allows us to have memory protection, because each virtual address is
translated to a physical address.
Following are the situations, when entire program is not required to be loaded fully in main
memory.
User written error handling routines are used only when an error occurred in the
data or computation.
Certain options and features of a program may be used rarely.
Many tables are assigned a fixed amount of address space even though only a small
amount of the table is actually used.
The ability to execute a program that is only partially in memory would counter
many benefits.
Less number of I/O would be needed to load or swap each user program into
memory.
A program would no longer be constrained by the amount of physical memory that is
available.
Each user program could take less physical memory, more programs could be run the
same time, with a corresponding increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory management unit, or
MMU, is built into the hardware. The MMU’s job is to translate virtual addresses into physical
addresses. A basic example is given below −
Virtual memory is commonly implemented by demand paging. It can also be implemented in a
segmentation system. Demand segmentation can also be used to provide virtual memory.
Advantages of Virtual Memory
Virtual memory helps to gain speed when only a particular segment of the program
is required for the execution of the program.
It is very helpful in implementing a multiprogramming environment.
It allows you to run more applications at once.
It helps you to fit many large programs into smaller programs.
Common data or code may be shared between memory.
Process may become even larger than all of the physical memory.
Data / code should be read from disk whenever required.
The code can be placed anywhere in physical memory without requiring relocation.
More processes should be maintained in the main memory, which increases the
effective use of CPU.
Each page is stored on a disk until it is required after that, it will be removed.
It allows more applications to be run at the same time.
There is no specific limit on the degree of multiprogramming.
Large programs should be written, as virtual address space available is more
compared to physical memory.
Disadvantages of Virtual Memory
Here, are drawbacks/cons of using virtual memory:
Applications may run slower if the system is using virtual memory.
Likely takes more time to switch between applications.
Offers lesser hard drive space for your use.
It reduces system stability.
It allows larger applications to run in systems that don’t offer enough physical RAM
alone to run them.
It doesn’t offer the same performance as RAM.
It negatively affects the overall performance of a system.
Occupy the storage space, which may be used otherwise for long term data storage.
Demand Paging
A demand paging system is quite similar to a paging system with swapping where processes
reside in secondary memory and pages are loaded only on demand, not in advance. When a
context switch occurs, the operating system does not copy any of the old program’s pages out to
the disk or any of the new program’s pages into the main memory Instead, it just begins
executing the new program after loading the first page and fetches that program’s pages as they
are referenced.
While executing a program, if the program references a page which is not available in the main
memory because it was swapped out a little ago, the processor treats this invalid memory
reference as a page fault and transfers control from the program to the operating system to
demand the page back into the memory.
Advantages
Following are the advantages of Demand Paging −
Large virtual memory.
More efficient use of memory.
There is no limit on degree of multiprogramming.
Disadvantages
Number of tables and the amount of processor overhead for handling page
interrupts are greater than in the case of the simple paged management techniques.
Page Replacement Algorithm
Page replacement algorithms are the techniques using which an Operating System decides which
memory pages to swap out, write to disk when a page of memory needs to be allocated. Paging
happens whenever a page fault occurs and a free page cannot be used for allocation purpose
accounting to reason that pages are not available or the number of free pages is lower than
required pages.
When the page that was selected for replacement and was paged out, is referenced again, it has to
read in from disk, and this requires for I/O completion. This process determines the quality of the
page replacement algorithm: the lesser the time waiting for page-ins, the better is the algorithm.
A page replacement algorithm looks at the limited information about accessing the pages
provided by hardware, and tries to select which pages should be replaced to minimize the total
number of page misses, while balancing it with the costs of primary storage and processor time of
the algorithm itself. There are many different page replacement algorithms. We evaluate an
algorithm by running it on a particular string of memory reference and computing the number of
page faults,
Reference String
The string of memory references is called reference string. Reference strings are generated
artificially or by tracing a given system and recording the address of each memory reference. The
latter choice produces a large number of data, where we note two things.
For a given page size, we need to consider only the page number, not the entire
address.
If we have a reference to a page p, then any immediately following references to
page pwill never cause a page fault. Page p will be in memory after the first
reference; the immediately following references will not fault.
For example, consider the following sequence of addresses −
123,215,600,1234,76,96
If page size is 100, then the reference string is 1,2,6,12,0,0
First In First Out (FIFO) algorithm
Oldest page in main memory is the one which will be selected for replacement.
Easy to implement, keep a list, replace pages from the tail and add new pages at the
head.
UNIT-III
: I/O Device Management
I/O Device Management
Many different I/O devices are used in modern computer system. For example, disks,
printers, keyboard, network interface cards etc.
Some examples are purely input and some are purely output and others are both
input output. For example ,a keyword is an input only device, a display monitor is an
output only device and a disk is an input output device.
The devices are normally manipulated by special software programs called device
drivers.
Some devices store data temporarily and transfer data from one hardware
component to other and some devices store data permanently and are called
storage devices.
I/O Devices
The system I/O devices generally fall into three categories on the basis of how the devices are
managed and allocated by an operating system:
Dedicated Devices
Dedicated devices are those which are assigned to a single process at a times by an
operating system
The process keeps this device until it terminates.
There are certain devices which can be used only in dedicated manner and cannot
be shared. For example, tape devices and plotters etc.
Shared devices
Shared devices are shared amongst several processes at a time by interleaved
execution.
This interleaving of process requests is controlled by device manager.
However, if two processes requests the same device at the same time, conflict can
be resolved by using some policy that decides which request should be entertained
first.
Virtual devices
SPOOLing (simultaneous peripheral operations on line) technique can be used to
convert dedicated devices like card readers and printers into shared
For example, a spooling program can read and copy all card input onto a disk a high
speed.Later,when a process tries to read a card, the spooling program intercepts the
request and converts it to a read from the disk.
This technique can be applied to various other devices such as printers’ teletypes
and most dedicated slow input/output devices.
Device Controllers
Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all I/O
devices.
The Device Controller works like an interface between a device and a device driver.
I/O units (Keyboard, mouse, printer, etc.) typically consist of a mechanical
component and an electronic component where electronic component is called the
device controller.
There is always a device controller and a device driver for each device to
communicate with the Operating Systems. A device controller may be able to handle
multiple devices. As an interface its main task is to convert serial bit stream to block
of bytes, perform error correction as necessary.
Any device connected to the computer is connected by a plug and socket, and the
socket is connected to a device controller. Following is a model for connecting the
CPU, memory, controllers, and I/O devices where CPU and device controllers all use a
common bus for communication.
Device Drivers
Device Driver in computing refers to a special kind of software program or a specific type of
software application which controls a specific hardware device that enables different hardware
devices for communication with the computer’s Operating System
A device driver communicates with the computer hardwares by computer subsystem or computer
bus connected to the hardware.
Device Drivers are very essential for a computer system to work properly because without device
driver the particular hardware fails to work accordingly means it fails in doing a particular
function/action for which it has been created.
In a very common way most term it as only a Driver also when someone says Hardware
Driver that also refers to this Device Driver.
Disk Storage
Disk is a secondary storage device that is used to store data.
The external devices such as hard disk,magnetic disks and floppy disks stores data in
the sectors.
These devices provide the data to user programs by means of I/O requests.
Disk management is an important function of operating system and includes disk
scheduling, disk buffering and management of swap area and disk cache.
Disk scheduling
Disk scheduling is done by operating systems to schedule I/O requests arriving for the disk. Disk
scheduling is also known as I/O scheduling.
Disk scheduling is important because:
Multiple I/O requests may arrive by different processes and only one I/O request can
be served at a time by the disk controller. Thus other I/O requests need to wait in the
waiting queue and need to be scheduled.
Two or more request may be far from each other so can result in greater disk arm
movement.
Hard drives are one of the slowest parts of the computer system and thus need to be
accessed in an efficient manner.
There are many Disk Scheduling Algorithms but before discussing them let’s have a quick look at
some of the important terms:
Seek Time
Seek time is the time taken in locating the disk arm to a specified track where the read/write
request will be satisfied.
Rotational Latency
It is the time taken by the desired sector to rotate itself to the position from where it can access
the R/W heads.
Transfer Time
It is the time taken to transfer the data.
Disk Access Time
Disk access time is given as,
Disk Access Time = Rotational Latency + Seek Time + Transfer Time
Disk Response Time
It is the average of time spent by each request waiting for the IO operation.
Purpose of Disk Scheduling
The main purpose of disk scheduling algorithm is to select a disk request from the queue of IO
requests and decide the schedule when this request will be processed.
Goal of Disk Scheduling Algorithm
Fairness
High throughout
Minimal traveling head time
Disk Scheduling Algorithms
The list of various disks scheduling algorithm is given below. Each algorithm is carrying some
advantages and disadvantages. The limitation of each algorithm leads to the evolution of a new
algorithm.
FCFS scheduling algorithm
SSTF (shortest seek time first) algorithm
SCAN scheduling
C-SCAN scheduling
LOOK Scheduling
C-LOOK scheduling
FCFS Scheduling Algorithm
It is simplest form of disk scheduling algorithm
Request that arrives first will be served first.
It processes the I/O requests in the sequential order i.e in the same order as they
arrive.
This method improves the response time as a request gets response in fair amount
of time.
However ,the throughput is not efficient and this algorithm fails to decrease the
average seek time.
It involves a lot of random hard movements and disk rotations.
Disadvantages
The scheme does not optimize the seek time.
The request may come from different processes therefore there is the possibility of
inappropriate movement of the head.
Example
Consider the following disk request sequence for a disk with 100 tracks 45, 21, 67, 90, 4, 50, 89,
52, 61, 87, 25
Head pointer starting at 50 and moving in left direction. Find the number of head movements in
cylinders using FCFS scheduling.
Solution
Shortest seek time First (SSTF) scheduling
Shortest seek time first (SSTF) algorithm selects the disk I/O request which requires the least disk
arm movement from its current position regardless of the direction. It reduces the total seek time
as compared to FCFS.
It allows the head to move to the closest track in the service queue.
Advantages
It provides better performance than FIFO and produces less number of head
movements.
Throughput is higher as compared to FIFO.
SSTF is useful in batch processing system where throughput is major consideration.
Disadvantages
It may cause starvation for some requests.
Switching direction on the frequent basis slows the working of algorithm.
It is not the most optimal algorithm.
Example
Consider the following disk request sequence for a disk with 100 tracks
45, 21, 67, 90, 4, 89, 52, 61, 87, 25
Head pointer starting at 50. Find the number of head movements in cylinders using SSTF
scheduling.
Solution:
SCAN Scheduling
It is also called as Elevator Algorithm. In this algorithm, the disk arm moves into a particular
direction till the end, satisfying all the requests coming in its path,and then it turns backend
moves in the reverse direction satisfying requests coming in its path.
It works in the way an elevator works, elevator moves in a direction completely till the last floor
of that direction and then turns back.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using SCAN scheduling.
Number of Cylinders = 40 + 14 + 65 + 13 + 20 + 24 + 11 + 4 + 46 = 237
Advantages of SCAN Scheduling
Throughput is better than FIFO.
It also considers the starvation of request. In this regard it is better than SSTF.
Disadvantages of scan scheduling
The major drawback of this policy is that the disk arm always stars from the
beginning, no matter other number of requests are present on the other end of disk.
C-SCAN Scheduling
In C-SCAN algorithm, the arm of the disk moves in a particular direction servicing requests until
it reaches the last cylinder, then it jumps to the last cylinder of the opposite direction without
servicing any request then it turns back and start moving in that direction servicing the remaining
requests.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C-SCAN scheduling.
No. of cylinders crossed = 40 + 14 + 199 + 16 + 46 + 4 + 11 + 24 + 20 + 13 = 387
LOOK Scheduling
It is like SCAN scheduling Algorithm to some extant except the difference that, in this scheduling
algorithm, the arm of the disk stops moving inwards (or outwards) when no more request in that
direction exists. This algorithm tries to overcome the overhead of SCAN algorithm which forces
disk arm to move in one direction till the end regardless of knowing if any request exists in the
direction or not.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using LOOK scheduling.
Number of cylinders crossed = 40 + 51 + 13 + +20 + 24 + 11 + 4 + 46 = 209
C Look Scheduling
C Look Algorithm is similar to C-SCAN algorithm to some extent. In this algorithm, the arm of
the disk moves outwards servicing requests until it reaches the highest request cylinder, then it
jumps to the lowest request cylinder without servicing any request then it again start moving
outwards servicing the remaining requests.
It is different from C SCAN algorithm in the sense that, C SCAN force the disk arm to move till
the last cylinder regardless of knowing whether any request is to be serviced on that cylinder or
not.
Example
Consider the following disk request sequence for a disk with 100 tracks
98, 137, 122, 183, 14, 133, 65, 78
Head pointer starting at 54 and moving in left direction. Find the number of head movements in
cylinders using C LOOK scheduling.
File Management
File Management
File management is the process of storing, controlling and managing data stored on
disks or secondary storage in the form of files.
File management ensures the consistency of data when multiple users access files
concurrently.
File management also provides the measures for file security and protection.
File Concept
A file is a logical collection of information stored on secondary storage such as hard
disk.
Physically, a file is the smallest allotment of secondary storage device e.g. disk.
Logically, a file is a sequence of logical records i.e. a sequence of bits and bytes.
Files can be used to contain data and programs
Data files can be numneric, alphabetic, alohanumeric or binary.
A files has various attributes like name, type, location, size, protection, time and date
of creation etc.
File naming
A file can be given a name for the convenience of its use by its creator.
A name is attached to every file so as to uniquely identify it and access it through its
name.
The exact rules for naming file vary from system to system but all the operating
systems allow string of one to eight letters as legal file name.
Digits and few special characters are also allowed in file names.
Some systems differentiate between uppercase and lower case characters in names,
whereas other systems consider the two cases equivalent.
File Attributes
A file has a name and data. Moreover, it also stores Meta information like file creation date and
time, current size, last modified date, etc. All this information is called the attributes of a file
system.
Here, are some important File attributes used in OS:
Name:It is the only information stored in a human-readable form.
Identifier: Every file is identified by a unique tag number within a file system known
as an identifier.
Location:Points to file location on device.
Type:This attribute is required for systems that support various types of files.
Size. Attribute used to display the current file size.
Protection. This attribute assigns and controls the access rights of reading, writing,
and executing the file.
Time, date and security:It is used for protection, security, and also used for
monitoring
File operations
There are various operations which can be implemented on a file. We will see all of them in
detail.
1. Create
Creation of the file is the most important operation on the file. Different types of files are created
by different methods for example text editors are used to create a text file, word processors are
used to create a word file and Image editors are used to create the image files.
2. Write
Writing the file is different from creating the file. The OS maintains a write pointer for every file
which points to the position in the file from which, the data needs to be written.
3. Read
Every file is opened in three different modes : Read, Write and append. A Read pointer is
maintained by the OS, pointing to the position up to which, the data has been read.
4. Re-position
Re-positioning is simply moving the file pointers forward or backward depending upon the user’s
requirement. It is also called as seeking.
5. Delete
Deleting the file will not only delete all the data stored inside the file, It also deletes all the
attributes of the file. The space which is allocated to the file will now become available and can
be allocated to the other files.
6. Truncate
Truncating is simply deleting the file except deleting attributes. The file is not completely deleted
although the information stored inside the file get replaced.
Access methods
Sequential Access
Most of the operating systems access the file sequentially. In other words, we can say that most of
the files need to be accessed sequentially by the operating system.
In sequential access, the OS read the file word by word. A pointer is maintained which initially
points to the base address of the file. If the user wants to read first word of the file then the
pointer provides that word to the user and increases its value by 1 word. This process continues
till the end of the file.
Modern word systems do provide the concept of direct access and indexed access but the most
used method is sequential access due to the fact that most of the files such as text files, audio
files, video files, etc need to be sequentially accessed.
Advantages
System performance improves by direct transfer of data between memory and
I/O (Input/output) devices, by saving CPU the bothers.
CPU can utilize the saved time for performing the operations that do not require
system buses.
It also allows the random record deletion and insertion.
It allows faster updating of several files.
Disadvantage
The CPU is rendered inactive for long durations in case of burst mode data.
Only one key is used.
Data may be accidentally erased or overwritten unless special precautions are taken.
Indexed Access
If a file can be sorted on any of the filed then an index can be assigned to a group of certain
records. However, A particular record can be accessed by its index. The index is nothing but the
address of a record in the file.
In index accessing, searching in a large database became very quick and easy but we need to have
some extra space in the memory to store the index value.
Advantages:
It combines both sequential and direct
Suitable for sequential access and random access
Provides quick access to records
Disadvantages:
It uses special software and is expensive
Extra time is taken to maintain index
Extra storage for index files
Expensive hardware is required
Directory structures and management
What is a directory?
Directory can be defined as the listing of the related files on the disk. The directory may store
some or the entire file attributes.
To get the benefit of different file systems on the different operating systems, A hard disk can be
divided into the number of partitions of different sizes. The partitions are also called volumes or
mini disks.
Each partition must have at least one directory in which, all the files of the partition can be listed.
A directory entry is maintained for each file in the directory which stores all the information
related to that file.
A directory can be viewed as a file which contains the Meta data of the bunch of files.
Every Directory supports a number of common operations on the file:
1. File Creation
2. Search for the file
3. File deletion
4. Renaming the file
5. Traversing Files
6. Listing of files
Logical Structure of a directory
A directory is a container that is used to contain folders and files. It organizes files and folders in
a hierarchical manner.
There are several logical structures of a directory, these are given below.
Single-level directory –
The single-level directory is the simplest directory structure. In it, all files are
contained in the same directory which makes it easy to support and understand.
A single level directory has a significant limitation, however, when the number of files increases
or when the system has more than one user. Since all the files are in the same directory, they must
have a unique name. if two users call their dataset test, then the unique name rule violated.
Advantages:
Since it is a single directory, so its implementation is very easy.
If the files are smaller in size, searching will become faster.
The operations like file creation, searching, deletion, updating are very easy in such a
directory structure.
Disadvantages:
There may chance of name collision because two files can not have the same name.
Searching will become time taking if the directory is large.
This can not group the same type of files together.
Two-level directory
As we have seen, a single level directory often leads to confusion of files names among different
users. the solution to this problem is to create a separate directory for each user.
In the two-level directory structure, each user has their own user files directory (UFD). The UFDs
have similar structures, but each lists only the files of a single user. system’s master file directory
(MFD) is searches whenever a new user id=s logged in. The MFD is indexed by username or
account number, and each entry points to the UFD for that user.
Advantages:
We can give full path like /User-name/directory-name/.
Different users can have the same directory as well as the file name.
Searching of files becomes easier due to pathname and user-grouping.
Disadvantages:
A user is not allowed to share files with other users.
Still, it not very scalable, two files of the same type cannot be grouped together in the
same user.
Tree-structured directory
once we have seen a two-level directory as a tree of height 2, the natural generalization is to
extend the directory structure to a tree of arbitrary height.
This generalization allows the user to create their own subdirectories and to organize their files
accordingly.
A tree structure is the most common directory structure. The tree has a root directory, and every
file in the system has a unique path.
Advantages:
Very general, since full pathname can be given.
Very scalable, the probability of name collision is less.
Searching becomes very easy, we can use both absolute paths as well as relative.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved into multiple
directories.
We can not share files.
It is inefficient, because accessing a file may go under multiple directories.
Acyclic graph directory –
An acyclic graph is a graph with no cycle and allows us to share subdirectories and files. The
same file or subdirectories may be in two different directories. It is a natural generalization of the
tree-structured directory.
It is used in the situation like when two programmers are working on a joint project and they need
to access files. The associated files are stored in a subdirectory, separating them from other
projects and files of other programmers since they are working on a joint project so they want the
subdirectories to be into their own directories. The common subdirectories should be shared. So
here we use Acyclic directories.
It is the point to note that the shared file is not the same as the copy file. If any programmer
makes some changes in the subdirectory it will reflect in both subdirectories.
Advantages:
We can share files.
Searching is easy due to different-different paths.
Disadvantages:
We share the files via linking, in case deleting it may create the problem,
If the link is a soft link then after deleting the file we left with a dangling pointer.
In the case of a hard link, to delete a file we have to delete all the references
associated with it.
General graph directory structure
In general graph directory structure, cycles are allowed within a directory structure where
multiple directories can be derived from more than one parent directory.
The main problem with this kind of directory structure is to calculate the total size or space that
has been taken by the files and directories.
Advantages:
It allows cycles.
It is more flexible than other directories structure.
Disadvantages:
It is more costly than others.
It needs garbage collection
Remote File System
Files can be shared across the network via variety of methods –
Using FTP i.e., file transfer protocol is used to transfer file from one computer to
other.
Using distributed file system (DFS) in which remote directories are visible from local
machine.
Using Remote File System (RFS) in which the arrival of networks has allowed
communication between remote computers. These networks allows various hardware
and software resources to be shared throughout the world.
Client-server model
Remote file system allows a computer to mount one or more file systems from one or
more remote machines.
In this case, the machine containing the files is server and the machine wanting access
to the files is the client.
The server specifies which file can be accessed by a particular client.
Files are usually specified on a partition or subdirectory level.
A server can serve multiple clients, and a client can access multiple servers,
depending on the implementation details of a given client server facility.
Once the remote file system is mounted, file operation requests are sent on the behalf
of the user to the server, via network using DFS protocol
Distributed Information System
In order to manage client/server services easily, a system called distributed
information system or distributed naming service exists that provide unified access to
the information needed for remote computing.
Domain name system provides host name to network address translations for the
entire internet.
Sun Microsoft developed yellow pages (renamed to network information service),
that centralized the storage of user names, host names, printer information etc.
Now a days lightweight directory access protocol access protocol is being used. It is
secure distributed naming mechanism.
Protection in File System
In computer systems, alot of user’s information is stored, the objective of the operating system is
to keep safe the data of the user from the improper access to the system. Protection can be
provided in number of ways. For a single laptop system, we might provide protection by locking
the computer in a desk drawer or file cabinet. For multi-user systems, different mechanisms are
used for the protection.
Types of Access:
The files which have direct access of the any user have the need of protection. The files which are
not accessible to other users doesn’t require any kind of protection. The mechanism of the
protection provides the facility of the controlled access by just limiting the types of access to the
file. Access can be given or not given to any user depends on several factors, one of which is the
type of access required. Several different types of operations can be controlled:
Read
Reading from a file.
Write
Writing or rewriting the file.
Execute
Loading the file and after loading the execution process starts.
Append
Writing the new information to the already existing file, editing must be end at the
end of the existing file.
Delete
Deleting the file which is of no use and using its space for another data.
List
List the name and attributes of the file.
Operations like renaming, editing the existing file, copying; these can also be controlled. There
are many protection mechanisms. Each of them mechanism have different advantages and
disadvantages and must be appropriate for the intended application.
Access Control
It is the most common approach to protect the files and directories depending upon
the identity if the users.
Access control limits who can access files and how they can access them.
Typically, users or group of users are granted certain access rights to a file.
Following are the different operations that are possible on a file
Read– Reading information contained in the file.
Write-writing new information into a file at any point or overwriting EXISTING
INFORMATION IN A FILE.
Append- Writing new information only at the end of the file. However, modifying or
deleting any content is not allowed under this operation.
Delete- deleting a file from a file system and releasing its storage space for use in
other files.
List- Reading or listing the name and attributes of a files or directory.
Execute- Loading the file into the memory and executing it.
Rename- changing the name of a file.
Update- It include modifying, deleting and adding to the file.
Copy– Copying the contents of the file to another file.
Password Protection
Another approach to protect a file form an unauthorized access is to use a password
with each file.
The owner of a file can control its access by assigning a password. Thus, only those
users who know the password, can access a particular file.
UNIT-IV
Introduction to Distributed Operating system
Distributed Operating System
These types of the operating system is a recent advancement in the world of computer technology
and are being widely accepted all over the world and, that too, with a great pace. Various
autonomous interconnected computers communicate with each other using a shared
communication network. Independent systems possess their own memory unit and CPU. These
are referred to as loosely coupled systems or distributed systems. These system’s processors
differ in size and function. The major benefit of working with these types of the operating system
is that it is always possible that one user can access the files or software which are not actually
present on his system but some other system connected within this network i.e., remote access is
enabled within the devices connected in that network.
3. Openness:
Another important goal of distributed systems is openness. An open distributed
system is a system that offers services in standards that describable the syntax and
semantics of those service instances, standard rules in computer networks control the
format, content, and meaning of messages sent and received. Such rules are
formalized in the protocols. In distributed systems, services are typically specified
through interfaces, often called interface definition languages (IDL). Interface
definitions written in IDL almost always capture only the syntax of services. They
accurately specify the names of functions that are available with the types of
parameters, return values, possible exceptions that can be raised and so on.
4. Scalability:
The uncertain trend in distributed systems is towards larger systems. This observation
has implications for distributed file system design. Algorithms that work well for
systems with 100 machines can work for systems with 1000 machines and none at all
for systems with 10, 000 machines. for starters, the centralized algorithm does not
scale well. If opening a file requires contacting a single centralized server to record
the fact that the file is open then the server will eventually become a bottleneck as the
system grows.
5. Reliability:
The main goal of building distributed systems was to make them more reliable than
single processor systems. The idea is that if some machine goes down, some other
machine gets used to it. In other words, theoretically the reliability of the overall
system can be a Boolean OR of the component reliability. For example, with four file
servers, each with a 0.95 chance of being up at any instant, the probability of all four
being down simultaneously is 0.000006, so the probability of at least one being
available is (1-0.000006)= 0.999994, far better than any individual server.
6. Performance:
Building a transparent, flexible, reliable distributed system is useless if it is slow like
molasses. In particular application on a distributed system, it should not deteriorate
better than running some application on a single processor. Various performance
metrics can be used. Response time is one, but so are throughput, system utilization,
and amount of network capacity consumed. Furthermore, The results of any
benchmark are often highly dependent on the nature of the benchmark. A benchmark
involves a large number of independent highly CPU-bound computations which give
radically different results than a benchmark that consists of scanning a single large
file for same pattern.
Types of Multiprocessors
There are mainly two types of multiprocessors i.e. symmetric and asymmetric multiprocessors.
Details about them are as follows −
Symmetric Multiprocessors
In these types of systems, each processor contains a similar copy of the operating system and they
all communicate with each other. All the processors are in a peer to peer relationship i.e. no
master – slave relationship exists between them.
An example of the symmetric multiprocessing system is the Encore version of UNIX for the
Multimax Computer.
Asymmetric Multiprocessors
In asymmetric systems, each processor is given a predefined task. There is a master processor that
gives instruction to all the other processors. Asymmetric multiprocessor system contains a master
slave relationship.
Asymmetric multiprocessor was the only type of multiprocessor available before symmetric
multiprocessors were created. Now also, this is the cheaper option.
Advantages of Multiprocessor Systems
There are multiple advantages to multiprocessor systems. Some of these are −
More reliable Systems
In a multiprocessor system, even if one processor fails, the system will not halt. This ability to
continue working despite hardware failure is known as graceful degradation. For example: If
there are 5 processors in a multiprocessor system and one of them fails, then also 4 processors are
still working. So the system only becomes slower and does not ground to a halt.
Enhanced Throughput
If multiple processors are working in tandem, then the throughput of the system increases i.e.
number of processes getting executed per unit of time increase. If there are N processors then the
throughput increases by an amount just under N.
More Economic Systems
Multiprocessor systems are cheaper than single processor systems in the long run because they
share the data storage, peripheral devices, power supplies etc. If there are multiple processes that
share data, it is better to schedule them on multiprocessor systems with shared data than have
different computer systems with multiple copies of the data.
Disadvantages of Multiprocessor Systems
There are some disadvantages as well to multiprocessor systems. Some of these are:
Increased Expense
Even though multiprocessor systems are cheaper in the long run than using multiple computer
systems, still they are quite expensive. It is much cheaper to buy a simple single processor system
than a multiprocessor system.
Complicated Operating System Required
There are multiple processors in a multiprocessor system that share peripherals, memory etc. So,
it is much more complicated to schedule processes and impart resources to processes. than in
single processor systems. Hence, a more complex and complicated operating system is required
in multiprocessor systems.
Large Main Memory Required
All the processors in the multiprocessor system share the memory. So a much larger pool of
memory is required as compared to single processor systems.
UMA programs can run without change in NUMA machines but performance may be slow.
Memory access time depends on the memory location which is relative to a processor. The
processor can access it’s own local memory fastly than it’s non-local memory. NUMA is used in
a symmetric multiprocessing system.
SMP is obviously tightly coupled and shares everything in multiple processors by using a single
operating system. NUMA has three key properties.
1. Access to remote memory is possible.
2. Accessing remote memory is slower than local memory.
iii. Remote access time is not hidden by the caching.
The following figure shows the structure of NUMA. In this CPU and memory is connected to
MMU (Memory management unit) via local bus and local memory connected to the system bus
via local bus.
NUMA Structure
Fig: NUMA structure
It is used in SMP. Multiprocessor system without NUMA create the problem of cache missed and
only one processor can access the computer memory at a time. To solve this problem, separate
memory is provided for each processor.
There are 2 types of NUMA
1. NC-NUMA:
When the time to accessing a remote is not hidden, the system is called as NC-NUMA (Non-
Caching-Non-Uniform Memory Access). In this type of NUMA, processors have no local cache.
Cache coherence problem is not present in NC-NUMA. Each memory item is in a single location.
Remote memory access is difficult so this system helps to the software’s those are relocated
memory pages from one block to another just for improving the performance. A page scanner
demon activates every few seconds, examines statistics on memory usage, and moves pages from
one block to another. The Figure is the NC-NUMA type structure.
1. CC- NUMA:
When a coherent cache is present, the system is called as CC-NUMA (Cache Coherent-Non
Uniform Memory Access). CC-NUMA uses the directory based protocol rather than snooping.
The basic idea is to manage each node in the system with a directory for its RAM blocks. A
database tells that in which cache is located a RAM block, and what is its state.
Synchronization & Scheduling
In multiple-processor scheduling multiple CPU’s are available and hence Load Sharing becomes
possible. However multiple processor scheduling is more complex as compared to single
processor scheduling. In multiple processor scheduling there are cases when the processors are
identical i.e. HOMOGENEOUS, in terms of their functionality, we can use any processor
available to run any process in the queue.
There are some extra features which multiprocessor perform:
Process synchronization
Resource management
Scheduling
There are various organizations of multiprocessor operating system:
1. Each CPU has its own OS
In this types of the organization then there are much Central processing units in the system and
each CPU has its own private operating system and memory is shared among all the processors
and input-output system are also shared. All the system is connected by the single bus.
3. Symmetric multiprocessor
Symmetric Multiprocessors (SMP) is the third model. In this model, there is one copy of the OS
in memory, but any central processing unit can run it. Now, when a system call is made, then the
central processing unit on which the system call was made traps to the kernel and then processes
that system call. This model balances processes and memory dynamical. This approach uses
Symmetric Multiprocessing where each processor is self-scheduling. The scheduling proceeds
further by having the scheduler for each processor examine the ready queue and select a process
to execute. In this system, this is possible that all the process may be in common ready queue or
each processor may have its own private queue for the ready process.
There are mainly three sources of contention that can be found in a multiprocessor
operating system.
Locking system
As we know that the resources are shared in the multiprocessor system so there is a
need to protect these resources for safe access among the multiple processors. The
main purpose of locking scheme is to serialize access of the resources by the
multiple processors.
Shared data
When the multiple processor access the same data at the same time then there may
be a chance of inconsistency of data so to protect this we have to use some
protocols or locking scheme.
Cache coherence
It is the shared resource data which is stored in the multiple local caches. Suppose there are two
clients have a cached copy of memory and one client change the memory block and the other
client could be left with invalid cache without notification of the change so this kind of conflict
can be resolved by maintaining a coherence view of the data
Introduction to Real-Time Operating System
Real-Time Operating System
These types of OSs serve real-time systems. The time interval required to process and respond to
inputs is very small. This time interval is called response time.
Real-time systems are used when there are time requirements that are very strict like missile
systems, air traffic control systems, robots, etc.
Advantages of RTOS:
Maximum Consumption:Maximum utilization of devices and system, thus more
output from all the resources
Task Shifting:The time assigned for shifting tasks in these systems are very less. For
example, in older systems, it takes about 10 microseconds in shifting one task to
another, and in the latest systems, it takes 3 microseconds.
Focus on Application:Focus on running applications and less importance to
applications which are in the queue.
Real-timeoperating system in the embedded system: Since the size of programs are
small, RTOS can also be used in embedded systems like in transport and others.
Error Free:These types of systems are error-free.
Memory Allocation:Memory allocation is best managed in these types of systems.
Disadvantages of RTOS:
Limited Tasks:Very few tasks run at the same time and their concentration is very
less on few applications to avoid errors.
Use heavy system resources:Sometimes the system resources are not so good and
they are expensive as well.
Complex Algorithms:The algorithms are very complex and difficult for the designer
to write on.
Device driver and interrupt signals:It needs specific device drivers and interrupts
signals to respond earliest to interrupts.
Thread Priority:It is not good to set thread priority as these systems are very less
prone to switching tasks.
Examples of Real-Time Operating Systems are: Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic control systems, etc.
Characteristics of Real-time System:
Following are the some of the characteristics of Real-time System:
1. Time Constraints:
Time constraints related with real-time systems simply means that time interval
allotted for the response of the ongoing program. This deadline means that the task
should be completed within this time interval. Real-time system is responsible for the
completion of all tasks within their time intervals.
2. Correctness:
Correctness is one of the prominent part of real-time systems. Real-time systems
produce correct result within the given time interval. If the result is not obtained
within the given time interval then also result is not considered correct. In real-time
systems, correctness of result is to obtain correct result in time constraint.
3. Embedded:
All the real-time systems are embedded now-a-days. Embedded system means that
combination of hardware and software designed for a specific purpose. Real-time
systems collect the data from the environment and passes to other components of the
system for processing.
4. Safety:
Safety is necessary for any system but real-time systems provide critical safety. Real-
time systems also can perform for a long time without failures. It also recovers very
soon when failure occurs in the system and it does not cause any harm to the data and
information.
5. Concurrency:
Real-time systems are concurrent that means it can respond to a several number of
processes at a time. There are several different tasks going on within the system and it
responds accordingly to every task in short intervals. This makes the real-time
systems concurrent systems.
6. Distributed:
In various real-time systems, all the components of the systems are connected in a
distributed way. The real-time systems are connected in such a way that different
components are at different geographical locations. Thus all the operations of real-
time systems are operated in distributed ways.
7. Stability:
Even when the load is very heavy, real-time systems respond in the time constraint
i.e. real-time systems does not delay the result of tasks even when there are several
task going on a same time. This brings the stability in real-time systems.