You are on page 1of 47

Operating System Structure

An operating system is a design that enables user application programs to communicate with the hardware of the
machine. The operating system should be built with the utmost care because it is such a complicated structure and
should be simple to use and modify. Partially developing the operating system is a simple approach to accomplish
this. Each of these components needs to have distinct inputs, outputs, and functionalities.

Here we discuss many sorts of structures that implement operating systems, as listed below, as well as how and why
they work. It also defines the operating system structure.
o Simple Structure o Layered Approach Structure o Exo-Kernel Structure
o Monolithic Structure o Micro-Kernel Structure o Virtual Machines

What is an operating System Structure?


We want a clear structure to let us apply an operating system to our particular needs because operating systems have
complex structures. It is easier to create an operating system in pieces, much as we break down larger issues into
smaller, more manageable subproblems. Every segment is also a part of the operating system. Operating system
structure can be thought of as the strategy for connecting and incorporating various operating system components
within the kernel. Operating systems are implemented using many types of structures, as will be discussed below:

SIMPLE STRUCTURE
It is the most straightforward operating system structure, but it lacks definition and is only appropriate for usage with
tiny and restricted systems. Since the interfaces and degrees of functionality in this structure are clearly defined,
programs can access I/O routines, which may result in unauthorized access to I/O procedures.
This organizational structure is used by the MS-DOS operating system:
o Four layers make up the MS-DOS operating system, and each has its own set of features.
o These layers include ROM BIOS device drivers, MS-DOS device drivers, application programs, and system
programs.
o The MS-DOS operating system benefits from layering because each level can be defined independently and, when
necessary, can interact with one another.
o If the system is built in layers, it will be simpler to design, manage, and update. Because of this, simple structures
can be used to build constrained systems that are less complex.
o When a user program fails, the operating system as whole crashes.
o Because MS-DOS systems have a low level of abstraction, programs, and I/O procedures are visible to end users,
giving them the potential for unwanted access.

The following figure illustrates layering in a simple structure:

Advantages of Simple Structure:


o Because there are only a few interfaces and levels, it is simple to
develop.
o Because there are fewer layers between the hardware and the
applications, it offers superior performance.

Disadvantages of Simple Structure:


o The entire operating system breaks if just one user program
malfunctions.
o Since the layers are interconnected, and in communication with one
another, there is no abstraction or data hiding.
o The operating system's operations are accessible to layers, which can result in data tampering and system failure.

MONOLITHIC STRUCTURE
The monolithic operating system controls all aspects of the operating system's operation, including file management,
memory management, device management, and operational operations.
The core of an operating system for computers is called the kernel (OS). All other System components are provided
with fundamental services by the kernel. The operating system and the hardware use it as their main interface. When
an operating system is built into a single piece of hardware, such as a keyboard or mouse, the kernel can directly
access all of its resources.

The monolithic operating system is often referred to as the monolithic kernel. Multiple programming techniques such
as batch processing and time-sharing increase a processor's usability. Working on top of the operating system and
under the complete command of all hardware, the
monolithic kernel performs the role of a virtual
computer. This is an old operating system that was
used in banks to carry out simple tasks like batch
processing and time-sharing, which allows
numerous users at different terminals to access the
Operating System.

The following diagram represents the monolithic


structure:

Advantages of Monolithic Structure:


o Because layering is unnecessary and the kernel
alone is responsible for managing all
operations, it is easy to design and execute.
o Because functions like memory management, file management, process scheduling, etc., are implemented in the
same address area, the monolithic kernel runs rather quickly when compared to other systems. Utilizing the same
address speeds up and reduces the time required for address allocation for new processes.
Disadvantages of Monolithic Structure:
o The monolithic kernel's services are interconnected in address space and have an impact on one another, so if
any of them malfunctions, the entire system does as well.
o It is not adaptable. Therefore, launching a new service is difficult.

LAYERED STRUCTURE
The OS is separated into layers or levels in this kind of arrangement. Layer 0 (the lowest layer) contains the hardware,
and layer 1 (the highest layer) contains the user interface (layer N). These layers are organized hierarchically, with the
top-level layers making use of the capabilities of the lower-level ones.

The functionalities of each layer are separated in this method, and an


abstraction is also an option. Because layered structures are hierarchical,
debugging is simpler, therefore all lower-level layers are debugged before the
upper layer is examined. As a result, the presentation layer alone has to be
reviewed since all the lower layers have already been examined.
The image below shows how OS is organized into layers:

Advantages of Layered Structure:


o Work duties are separated since each layer has its functionality, and there
is some amount of abstraction.
o Debugging is simpler because the lower layers are examined first, followed
by the top layers.

Disadvantages of Layered Structure:


o Performance is compromised in layered structures due to layering.
o Construction of the layers requires careful design because the upper layers only make use of the lower layers'
capabilities.

MICRO-KERNEL STRUCTURE
The operating system is created using a micro-kernel framework that strips the kernel of any unnecessary parts.
Systems and user applications are used to implement these optional kernel components. So, Micro-Kernels is the
name given to these systems that have been developed.

Each Micro-Kernel is created separately and is kept apart from the others. As a result, the system is now more
trustworthy and secure. If one Micro-Kernel malfunctions, the remaining operating system is unaffected and
continues to function normally.
The image below shows Micro-Kernel Operating System Structure:

Advantages of Micro-Kernel Structure:


o It enables the portability of the operating system across
platforms.
o Due to the isolation of each Micro-Kernel, it is reliable and
secure.
o The reduced size of Micro-Kernels allows for successful testing.
o The remaining operating system remains unaffected and keeps
running properly even if a component or Micro-Kernel fails.

Disadvantages of Micro-Kernel Structure:


o The performance of the system is decreased by increased inter-module communication.
o The construction of a system is complicated.
EXOKERNEL
An operating system called Exokernel was created at MIT to offer application-level management of hardware
resources. The exokernel architecture's goal is to enable application-specific customization by separating resource
management from protection. Exokernel size tends to be minimal due to its limited operability.

Because the OS sits between the programs and the actual hardware, it will always affect the functionality,
performance, and breadth of the apps that are developed on it. By rejecting the idea that an operating system must
offer abstractions upon which to base applications, the exokernel operating system makes an effort to solve this
issue. The goal is to give developers as few restrictions on the use of abstractions as possible while yet allowing them
the freedom to do so when necessary.

Because of the way the exokernel architecture is designed, a single tiny kernel is responsible for moving all hardware
abstractions into unreliable libraries known as library operating systems. Exokernels differ from micro- and monolithic
kernels in that their primary objective is to prevent forced abstraction.

Exokernel operating systems have several features, including:


o Enhanced application control support.
o Splits management and security apart.
o A secure transfer of abstractions is made to an unreliable library operating system.
o Brings up a low-level interface.
o Operating systems for libraries provide compatibility and portability.

Advantages of Exokernel Structure:


o Application performance is enhanced by it.
o Accurate resource allocation and revocation enable more effective utilization of hardware resources.
o New operating systems can be tested and developed more easily.
o Every user-space program is permitted to utilize its customized memory management.

Disadvantages of Exokernel Structure:


o A decline in consistency
o Exokernel interfaces have a complex architecture.

VIRTUAL MACHINES (VMs)


The hardware of our personal computer, including the CPU, disc drives, RAM, and NIC (Network Interface Card), is
abstracted by a virtual machine into a variety of various execution contexts based on our needs, giving us the
impression that each execution environment is a separate computer. A virtual box is an example of it.

Using CPU scheduling and virtual memory techniques, an operating system allows us to execute multiple processes
simultaneously while giving the impression that each one is using a separate processor and virtual memory. System
calls and a file system is examples of extra functionalities that a process can have that the hardware is unable to give.
Instead of offering these extra features, the virtual machine method just offers an interface that is similar to that of
the most fundamental hardware. A virtual duplicate of the computer system underneath is made available to each
process.

We can develop a virtual machine for a variety of reasons, all of which are fundamentally connected to the capacity
to share the same underlying hardware while concurrently supporting various execution environments, i.e., various
operating systems.

Disk systems are the fundamental problem with the virtual machine technique. If the actual machine only has three-
disc drives but needs to host seven virtual machines, let's imagine that. It is impossible to assign a disc drive to every
virtual machine because the program that creates virtual machines would require a sizable amount of disc space to
offer virtual memory and spooling. The provision of virtual discs is the solution.
The result is that users get their virtual machines. They can then use any of the operating systems or software
programs that are installed on the machine below. Virtual machine software is concerned with programming
numerous virtual machines simultaneously into a physical machine; it is not required to take into account any user-
support software. With this configuration, it may be possible to break the challenge of building an interactive system
for several users into two manageable chunks.

Advantages of Virtual Machines:


o Due to total isolation between each virtual machine and every other virtual machine, there are no issues with
security.
o A virtual machine may offer an architecture for the instruction set that is different from that of actual computers.
o Simple availability, accessibility, and recovery convenience.

Disadvantages of Virtual Machines:


o Depending on the workload, operating numerous virtual machines simultaneously on a host computer may hurt
one of them.
o When it comes to hardware access, virtual computers are less effective than physical ones.

CONCLUSION
o The operating system makes it possible for the user to communicate with the hardware of the computer. The
operating system is used as the foundation for installing and using system software.
o The interconnections between the various operating system components can be defined as the operating system
structure.
o The operating system is divided into various structural types: simple structure, monolithic approach, layered
approach, micro-kernels, exokernels, and virtual machines.
o Each time one of these methods or structures changed, the OS became progressively better.
1.2 System components
As we know O/s provides the environment in which user can execute their programs. But we can see how O/s
performs the task. Internally O/s contains three different aspects, they are; showing the viewpoints of users,
programmers, and designers. By analyzing those three things we can create a system as large and complex as an O/s
by applying different programming methodologies not all systems have the same structure however all the systems
share the following objects as system components. They are:
i). Process management
ii). Main memory management
iii). File management
iv). I/O management
v). Secondary storage management
vi). Networking
vii). Protection system
viii). Command interpreter system

• Process management:
As we know, the program is a set of instructions that are executed by a CPU A process is a combination of a program
i.e. more than one job can form a process. So a process is a unit of work in a system which is a collection of programs.
The O/s is responsible for the following activities in connection with process management:
❖ Creation and deletion of both user and system processes
❖ Suspending and resuming the processes
❖ Providing mechanisms for process communication

• Main memory management:


During the execution time, the processes must be brought to the main memory from the disk. The main memory is a
large array of words/bytes. By using absolute addresses of memory, the instructions are executed. After finishing the
execution, the memory will be flushed and the next program can be loaded and executed. To improve the utilization
of the CPU and the speed of the devices, we must keep several processes in the main memory. There are different
schemes to manage main memory. The O/s is responsible for the following activities in connection with memory
management:
❖ Keeping track of which parts of memory are currently being used
❖ Deciding which processes are to be loaded into memory
❖ Allocate and de-allocate the memory space

• File management:
File management is one of the most visible components of an O/s. there are different mechanisms used to store
information which has their own characteristics and physical organization. We know a file is a collection of related
information i.e. program and data. This concept provides a mechanism how to access files with multiple users of a
system. The O/s is responsible for the following activities in connection with file management.
❖ Creating and deleting the files/directories
❖ Supporting primitives for manipulating files and directories
❖ Mapping files into secondary storage
❖ Backing up files

• I/O management:
We can not interact with the system without using I/O devices. One of the main purposes of an O/s is to hide the
peculiarities of specific I/O devices from the user. It means, O/s can only visualize the internal structure of an I/O
device including the working mechanism. So, it includes/consists:
❖ Memory management components like buffering, caching, and spooling
❖ Device driver interface
❖ Driver for specific hardware. Only the device driver knows the peculiarities of the specific device/hardware.
• Secondary storage management:
Because of the cost factor and its volatile nature, we can’t use primary memory as a storage location/space of the
system. It means there must be a secondary memory to keep a backup. During the execution time, every program
must be copied to the main memory from secondary storage. After executing the results again return to the
secondary storage. The operating system is responsible for the following activities in connection with disk
management:
❖ Free space management
❖ Storage allocation
❖ Disk scheduling

• Networking:
As we know the distributed system is a collection of processors that do not share the resources, memory, etc. in this
system every individual system contains its local memory. Via different communication tools, the systems are
connected. The main objective of this system is to share the resources mainly software to/from the remote location
computer.

• Command interpreter system:


It is an interface between the user and O/s. it means it can translate our request to that defined format which an O/s
understands and vice-versa. So it is acting as a protocol.

1.3 Operating system services


An O/s is a master control program of the system. It provides a mechanism that how to execute the program. So,
operating system services are provided for the convenience of the programmer to make the task easier. Following
are the main operating system services.
• Program execution: The system must be able to load a program, run it and terminate the process either normally
or abnormally.

• I/O operation: Every program needs I/O to perform its task. By using I/O devices we can perform the tasks.
Usually, users can’t control I/O devices directly. Therefore O/s handled I/O operation.

• File system management: Every program will return the value and also wants input from the user. As same this,
the program also needs to create and delete the file. Such types of tasks are handled by an O/s through this system.

• Communications: One process wants to interact with another to share the resource which is known as
communications. In this one can exchange information with another.

• Error detection: The main task of an O/s is to display an error message in a proper format. An error can be
generated through both hardware and software problems, i.e. it will detect both hardware and software.

• Resources allocation: Because of the cost-effectiveness, a system does not have much more resources. Without
getting the resources, a particular process can not complete its execution. The resources are divided into different
processes because resources are limited. So resources are the things that the processes request and it is done by the
operating system.

• Accounting: O/s always monitors the tasks i.e. which one gets the resources to run and which can’t get the
resources to execute. It means, this keeps a track of job records.

• Protection: Protection is a mechanism to hide things or resources or processes from unwanted users or processes.
It means, only owners of the system can handle the system.
Introduction to the Operating System
After pressing the main switch of a computer, a process called booting takes place automatically. Such things can
perform automatically through a master control program of a computer, which is known as the operating system.

There is no universally accepted definition of O/S. but its acts as a mediator between the system user and the
hardware i.e. peripherals of the system. The main objective of an O/S is to provide an environment/ platform on
which user can execute their programs conveniently and efficiently.

It is a resource allocator of a system i.e. without getting the resources from the O/S the particular process can not
execute/perform its task. So, O/S can manage CPU timing, memory space, storage space, I/O devices, etc. So, it is a
manager/supervisor/executive of a system. It is also used to prove the security of the system. Therefore, we can
define an O/S as the followings:
• It is a master control program • It is a supervisor of the system • It is an inspector of the system
• It is an environment variable • It is a manager of the system • It is a security center
• It is a resource allocator • It is an executive of the system

An operating system performs the following tasks:


• Provide user interface • Task management • Device management
• Job management • Process management • Providing security

1.1 Types/services of an Operating System:


MS-Dos, Windows 3x/95/98/2000/XP/NT, UNIX, Linux, Mac O/S, and OS2 are an example of the operating system.
The earliest operating system was developed in the late 1960s to manage tape drives. Later in the mid-1960, it
became an essential part of a system i.e. personal computer which is based upon timesharing, multi-threading, and
multitasking concepts. Depending upon the working principle of an O/S we can categorize it into many other
different types/systems. They are:
• Simple batch system • Time-sharing system • Distributed system
• Personal computer • Parallel system • Real-time system

a) Batch System (Simple & multi-programmed):


As we know device management is one of the main tasks of an O/S. Early computers were used a card reader and
tape drive as an I/O device, and a line printer is the most common output device. So users can't directly interact
with the system. In this situation, the user must be waited some time to get the result/output. It means, there is a
delay between job submission and completion which is known as turn-around-time.

During the execution time, the CPU became idle because the speed of the CUP and I/O devices are not the same. To
overcome this problem, the simple batch system used SPOOLING (Simultaneous Peripheral Operation On-Lining)
concept (1965 - 1980).

According to this concept, firstly O/S collects all the data/tasks/process/jobs from the input devices and saves it to
the disk. After this O/S would load as many as a job into the memory one after another until the available memory
could accommodate. Then the CPU is switching from one task to another and executes them. This situation i.e. after
adding the SPOOLING concepts to the Simple Batch System became multiprogramming. Following is the block
diagram of this concept:
INPUT CPU INPUT CPU OUTPUT
Card reader

DISK
CPU DISK
OUTPUT CPU
Line printer
SPOOLING concepts
Simple Batch System
b) Time-Sharing System:
In general terms, it refers to the allocation of time between more than one job. It is a logical extension of
multiprogramming. Typically, there are many jobs in the job pool that want to execute at a time but CUP can't
handle more than one job at a time. In this situation, the CPU can share the time slice between them equally. The
main objects of this system are to provide interactive use of the system at a reasonable cost i.e. time-sharing allows
users to share the computer and its resources simultaneously.

c) Parallel system:
In this system, there is more than one CPU that shares the same bus, memory, and I/O it is also known as a
multiprocessor system. In this one acts as a master processor and another becomes a slave. The master processor
handled the task first and allocates it to the slave t perform some task. In general practices, we did not use this
system. The main objective of this system is to increase reliability. In symmetric multiprocessing, each processor
runs identical copies of an O/S i.e. separately runs the system by sharing the resources.

d) Distributed System:
This is a new concept over there the processor doesn't share this memory i.e. each processor contains its local
memory. The connecting mechanism like a telephone line and high-speed bus was used to connect the different
individual systems to share the resources. But in a networking environment, different protocols are used to do so.
To achieve the following objectives we can use this system:
i. Resource sharing iii. Reliability
ii. Computation speedup iv. Communication

e) Real-time system:
This system is used when rigid time requirements have been placed. It means that within a defined time constraint
the CPU must execute that task. Mainly it is used to create flight simulators of the aircraft, scientific applications,
some major scientific pieces of equipment, etc.
In this system, sensors are used to bring the data. It has well-defined fixed time constraints, within that time frame
processing must be done. Depending upon the working principle of the system we can categorize this system into
two different categories. They are:
• Hard real-time: In this, within a given time frame the critical tasks must be executed. Such types of guarantees
were provided by the system. So time is a rigid factor over here. Aeronautical engineers and scientific
researchers have used this system.
• Soft real-time: It can set the priority over the critical task. Based on its priority the will be performed. So after
analyzing the condition we can set the priority to the processes. Hospitals and metrological pieces of equipment
are an example of this.
New Terminate
Process Concept
It is a primary mechanism for defining and managing the Create Interrupt Exit
execution of the program under the control of an OS. The
process is a dynamic concept that refers to a program in Ready Running
execution undergoing frequent state and attribute changes. On Resume
the other hand, an executable program is a static process that I/O event complete I/O event
may give to one or more processes. As we know a process is a Waiting
unit of work in a program i.e.

A process is more than the program code. It also includes the current activity as represented by the value of the
program counter and the contents of the processor's registers. A process generally also includes the process stack,
containing temporary data and a data section containing global variables.

1.1 Process state: A process is a unit of work in a program. During the program execution/process execution, it
changed the state. Those states of the process are also known as the current activity of the process. Following are
the different process states and the transition diagram process:
• New • Waiting • Termination
• Ready • Running

1.2 Process control block:


Each process is represented in an OS by a PCB which is known as a task control block. Whenever a process is
created, an OS creates a corresponding process control block, serving as its runtime description during the lifetime
of the process. Information stored in PCB and the block diagram of this is as follows. Process name
• Process name and id
Process ID/state
• Priority
• State of the process Process counter
• Memory management CPU registers
• IO status
• File management CPU scheduling
• A register save area Memory mgt.
• Accounting information of a process. IO management
Accounting inf.
1.3 Process scheduling
Processes
The objective of multiprogramming is to have some processes running at all times,
to maximize CPU utilization and the objective of the time-sharing is to switch the
CPU among processes so frequently that users can interact with each program while it is running. It means OS is
responsible for selecting the right process for the CPU. To do so different CPU scheduling algorithms are used.
1.4 Scheduling queues:
After creating the process it will directly enter into the job queue, which is a part of the main memory and they are
ready to execute but they are waiting for the resources. At that time such a process list is known as the ready
queue. Once the process is allocated to the CPU and is executing, one of the several events occurs. Mainly following
are those events:
• The process could create a new subprocess and wait for its Ready queue
CPU

termination.
• The process could issue an IO request and then be placed I/O IO queue IO request

in an IO queue.
Time slice
• The process could be removed forcibly from the CPU as a
result of an interruption and be put back in the ready Child executes Fork a child
queue.
Interrupt occurs Wait for an
Following is the common representation for the discussion of interrupt
process scheduling is a queuing diagram. n
Queuing diagram rep of process scheduling

1.5 Process synchronization:


In typical terminology, synchronization is the matching of timing between the components (H/W) of the
computer so that all are coordinated i.e. Join together. For instance, operations performed by the o/s are
generally synchronized i.e. to the internal system clock.

But in the case of process synchronization it is done by the CPU however CPU can execute more than one
process at a time but d time-sharing system arises to synchronize between them. There are two different
types of the process are:
a). Independent process: The concurrent process executed in the CPU may be either an independent or
cooperating process. A process is independent if it can’t affect or can’t be affected by the other process
executed in the CPU any process that doesn’t share any data with any other process is independent.
b). Co-operating process: On the other hand, a process is a co-operating process if it can affect or can be
affected by the other process executing in the system. Any process that shares data with other processes is d
cooperating process. There are several reasons for providing an environment that allows process co-
operation. They are:
• Information sharing: Since several users may be interested in the same piece of information (for instance
a shared file). We must provide an environment to allow concurrent access to these types of resources.
• Computation speedup: If we want a particular task to run faster we must break it into sub-task, each of
which will be executing in parallel with the other.
• Convenience: Even an individual uses may have a task to work on at a time. For instance, a user may be
editing, printing, and compiling in parallel.

1.6 Inter-process communication:


The ability of one process to communicate with another in a multitasking environment by using piping, semaphores,
shared memory, queues, mailbox, and message system mechanism is known as inter-process communication. It is
used to achieve process synchronization.

As same the cooperating process we can also achieve this within a process by dividing it into the different functions,
modules, procedures, etc. Following are some terms associated with the IPC.
• Message passing system: It is a mechanism that uses computer and data communication equipment to
convey messages from one location to another by using email, voice mail, fax, etc. In this we have to know
the following logical questions:
▪ How are the links established?
▪ Can a link be associated with more than two processes, functions, modules, procedures, etc?
▪ What is the capacity of a link?
▪ What is the size of the message?
▪ Is there an acknowledgment signal generated?
• Naming: It is a mechanism that refers to or identifies a process that wants to communicate with others by using
direct and indirect communication.

a. Direct communication: if processes P1 and P2 want to communicate, they must send messages to and receive
messages from each other. Indirect communication, the processes must explicitly name the sender and the
recipient processes. In this send and receive mechanisms are defined as follows:
▪ Send (P1, message): send a message to process P1.
▪ Receive (P2, message): receive a message from process P2.
▪ Receive (ID, message): receive a message from any process but it contains the process ID.

At that time every process needs to know the other’s identity to communicate which is responsible to generate an
acknowledgment signal from both sides.

b. Indirect communication: In this mechanism, the messages are sent to and received from different mailboxes or
ports which have a unique identity. Communication can be established by using the mailbox identity numbers
which are shared by more than one process. So the send and receive mechanisms are defined as follows:
▪ Send (A, message): send a message to mailbox A.
▪ Receive (A, message): receive a message from mailbox A.

At this time an operating system is responsible for the following operation on behalf of processes:
▪ To create a new mailbox
▪ To send and receive a message through the mailbox
▪ To delete the mailbox.
• Buffering: It is a temporary location i.e. Queue on which the message can exchange whenever the
communication can be direct or indirect. Such a temporary queue can be implemented in the following three
ways:
▪ Zero capacity: it means there is no message in the waiting queue.
▪ Bounded capacity: the capacity of the queue has a finite length. If the queue is full the sender must be delayed
until the space is available.

• Unbounded capacity: It has a queue with infinite length, so the number of messages can wait in it but the
sender never waits.

1.7 The critical section problem


It is a region in which the process shares the data, updating the table, changing the common variables, waiting for
files, and waiting for I/O is known as critical sections. Every process has its critical region, a section that has a
segment of code on which such types of operations are performed. When one process is in its critical section, no
other process is to be entered into its critical section. So at a time, only one process can enter into the critical
section.

Therefore each process has a segment of code called the critical section in which the process may be changing
common variables, updating tables, waiting for a file, etc. Typically, when one process is in its critical section, no
other is to be allowed to execute in its critical section and when processes access shared data, mutual exclusion is
to be forced. That is when an executing process leaves its critical section, and then only the other process waiting to
enter its critical section should be allowed to proceed.

So each process must request permission to enter its critical section. The section of code implementing this request
is the entry section. The critical section may be followed by an exit section. The remaining code is the reminder
section. By analyzing this we can draw the following general structure of the critical section in a form of an
algorithm.

Do {
Entry section
Critical section
Exit section
Reminder section
} while (1)

A solution to the critical section problem must satisfy the following three requirements:
▪ Mutual exclusion: if a process is executed in its critical section, then no other process can be executed in
the critical section.
▪ Progress: if no process is executing in its critical section and there exist some processes that wish to enter
their critical section then only those processes that are not executing in their reminder section can
participate in the critical section.
▪ Bounded waiting: there exists a bound on the number of times that other processes are allowed to enter
their critical section after a process has made a request to enter its critical section and before that request
is granted.

1.8 Classical problems of synchronization:


Mainly four different problems arise in the process synchronization. They are:
▪ Producer, consumer problem
▪ Producer, a consumer with a bounded buffer problem
▪ Producer, consumer problem with an unbounded buffer problem
▪ Reader, writer's problem
(i). Producer, consumer problem:
Even a set of cooperating processes, some of which produce data items to be consumed by another process that
behaves like a consumer, with the possible disparity between production and consumption rate. Processes often
tend to behave as a mixture of two rather than having a pure consumer or a pure producer.

(ii). Producer, a consumer with a bounded buffer problem:


The main problem in the bounded buffer is that both consumer and producer maybe stop in certain circumstances.
A consumer may acquire only produces items and must wait when no items are available.
Producers, on the other hand, may produce items only when there is an empty buffer otherwise new arrival might
overwrite the item produced earlier which is still waiting for consumption. At any particular time, the shared global
buffer may be empty. In another case, a producer may also be kept on waiting when the buffer is full.

(iii). Producer, a consumer with an unbounded buffer problem:


In the first attempt to solve the producer/ consumer problem, we assure that a buffer of unbounded capacity is set
aside to smooth the speed difference between producer and consumer. After the system is initialed a producer
must be the first process to run to produce the first item. For the point of the consumer, the process may run
whenever there is more than one item in the buffer produced but yet being consumed given the unbounded buffer
produce may run at any time without any restriction.

(iv). Reader, writer problem:


Reader and writer is a classical problem in concurrent process is using the shared global data are being accessed by
more than one process. The processed are categories depending on the user of the resources as either read or in
write mode. A reader never modifies a shared data structure. Whereas a writer may both read and write into it.
Several readers may use the shared data structure concurrently because no matter how they enter left the process
but writer, on the other hand, must be granted exclusive access to the data i.e. they can’t be interleaved satisfied
with either reading or writing.

In a set of co-operating processes, a producer process produces information that is consumed by a consumer
process. To allow producer and consumer processes to run concurrently, we must have available a buffer of items
that can be filled by the producer and emptied by the consumer. Sometimes a producer can produce one item while
the consumer is consuming another item. In that situation, the producer and consumer must be synchronized, so
that the consumer doesn’t try to consume an item that has not yet been produced. So the consumer must wait until
an item is produced.

Therefore a buffer plays a vital role over here. In the producer-consumer relationship with the unbounded buffer,
the consumer may have to wait for new items, but the producer can always produce new items. On the other hand,
in the producer-consumer relationship with the bounded buffer, the consumer must wait if the buffer is empty and
the producer must wait if the buffer is full. In this, the size of the buffer is fixed. The following algorithm suggests to
us the typical producer-consumer relationships.

1.9 Monitor:

shared data
Semaphore provides a powerful and flexible
tool for enforcing mutual exclusion and for the
cooperation process. It is difficult to produce a …
initialization code

correct program by using semaphore. The


difficulty is that waits and signal operations may
be scattered throughout a program and it is not Operations
easy to see the overall effect of these
operations by semaphore. Symmetric view of a monitor
So the monitor is a programming language construct that provides equivalent functionalities as that of a semaphore
and that is easier to control. The monitor construct has been implemented in several programming languages more
recently they have been implemented in the program library. Following is the block diagram of the monitor.

Generally following are the some characteristics of the monitor.


▪ The local data variables are accessible only by the monitor procedure and not by any other external procedure.
▪ A process enters the monitor by invoking one of the procedures.
▪ Only one process can able to execute on the monitor at a time. Any other process that has invoked the monitor
is suspended while waiting for the monitor to become available. Os the data variables in the monitor can be
acceded by only one process at a time. Thus a shared data structure can be protected by placing each on a
monitor.

1.10 Semaphore:
It is a synchronization tool used to generalize more complex problems. It is a protected integer variable whose value
can be altered and accessed only by operations P and V after its initialization. So the initialization of the semaphore
variables is known as the semaphore initialization.

The variable only can alter and be accessed through its two standard atomic transactions i.e. P and V. a semaphore
is an integer variable apart from its initialization. It is accessed only through two standard atomic operations i.e. “P”
for the wait and “V” for the signal. To transmit a signal by semaphore, then the process should execute the
preemptive signal.

To receive the signal by the semaphore is a process executing the preemptive wait, if the corresponding signal is not
yet been transmitted the process is suspended until the transmission takes place. Generally, there are two
processes/operations of a semaphore:
“P” operation with semaphore (S): “V” operation with semaphore (S):
If (S>0) then If (one or more processes are waiting on S) then
S=S-1 (Let one of these processes proceed)
Else (wait on S) Else (S=S+1)

So, the semaphore is implemented as the nucleus of the OS where process state switching is controlled.

CPU scheduling
The main purpose of the multi-user/multitasking OS is, to increase the CPU utilization i.e. To reduce the idleness
timing of the CPU. To do so we have to use a time-sharing system on behalf of CPU scheduling, that time-sharing
system is a type of OS as well as a type of CPU scheduling algorithm.

So the management or allocation of the CPU timing to the different processes/tasks/jobs refers to a CPU scheduling
that handles or executes more than one task at a time by switching the CPU between them.

1.1 CPU Schedulers:


A process of migrating the CPU from one task to another by using the various scheduling queues throughout the
lifetime of the process is known as a scheduler. So the scheduler selects from among the processes in memory that
are ready to execute and allocates the CPU to one of them, which is the main task of the short-term scheduler.
Following are the different terms related to the scheduler:
▪ Long-term scheduler: it is responsible for loading the different processes into the memory to execute.
▪ Short-term scheduling: it is also performing such tasks but it will load the particular task to the CPU which is
ready to execute.
▪ IO-bound: it spends more CPU time to take/collects an IO request from the IO devices rather than doing the
execution i.e. It spends more time on the users.
▪ CPU bound: it gives more time to compute the requests rather than giving more time to the users.
▪ Context switch: multitasking feature can be achieved only when the CPU switches to another process from the
first one. At that time OS requires to save the state of the old one and load the new process to execute which is
done by the context switch.
▪ Preemptive scheduling: schedule is said to be preemptive if the job can be taken away from the CPU. To make
preemptive effective more than one process must be kept in the main storage so that the next process is ready
for execution.
▪ Non-preemptive: scheduling is known as non-preemptive if once a process has been entered into the CPU, we
can’t take away that particular process until and unless completing its whole task.
▪ Dispatcher: It is the module that gives control of the CPU to the process selected by the short-term scheduler.

1.2 Scheduling criteria:


Different CPU scheduling algorithms have different properties and may favor one class of processes over another. In
choosing which algorithm is better to use in a particular situation of the various algorithms. It means many criteria
have been suggested for computing CPU scheduling algorithms. Following are some criteria that are used to
determine the best algorithm.
▪ CPU utilization: we want to keep the CPU as busy as possible. It varies from 0 to 100 %. In the real system, it
varies from 40 to 90 % i.e. 90% for the heavily loaded system. To achieve this we need to supply a proper device
and so on.
▪ Turn around time: the interval from the time of submission of a process to the time of completion is the
turnaround time. It is a sum of the periods spent waiting to get into the CPU and waiting in the ready queue for
executing and doing IO.
▪ Throughput: it is the one measure of work is the number of processes that are completed per time unit.
▪ Waiting time: the CPU scheduling algorithm doesn’t affect the amount of time during which a process executes
nor does IO, it affects only the amount of time that a process spends waiting in a ready queue. So it is the sum
of the periods spent waiting in the ready queue.
▪ Response time: in an interactive system, it is not the best creation. It is another measure is the time from
submission of a request until the first response is produced. This measure is called response time i.e. the
amount of time it takes to start responding but not the time that it takes to output that response.

1.3 CPU scheduling algorithms:


CPU scheduling deals with the problem of deciding the processes in the ready queue which one is to be allocated to
the CPU. There are many more scheduling algorithms to do so. Following are some important algorithms with short
descriptions:

• First come first served scheduling: The process that requests the CPU first allocated the CPU is known as FCFS.
It is the non-preemptive type of scheduling managed by the FIFO queue. When a process enters the ready queue,
its PCB is linked to the tail of the queue, and then when the CPU is free, it is allocated to the process at the head of
the queue. The running process is then removed from the queue. Following are the simple example of this
scheduling:
Process B_time WT for P1=0
P1 24 MS WT for P2=24
P2 12 MS WT for P3=36
P3 4 MS So, AWT=WT for (P1+P2+P3)/3=
n
Sol : Based on the FCFS method we can create the 60/3=20 MS
following Gantt chart:
TAT for P1=24
24 12 4 TAT for P2=36
P1 P2 P3 TAT for P3=40
So, ATAT=TAT for (P1+P2+P3)/3= 100/3=33.33 MS
0 24 36 40
Shortest job first scheduling: it is preemptive scheduling in which the waiting process with the smallest estimated
burst time (to complete) is run next. It reduces the average waiting time over FCFS. Following are the simple
example of this scheduling:
Process B_time WT for P1=16
P1 24 MS WT for P2=4
P2 12 MS WT for P3=0
P3 4 MS So, AWT=WT for (P1+P2+P3)/3=
n
Sol : Based on the SJF method we can create the 20/3=6.66 MS
following Gantt chart:
4 12 24 TAT for P1=40
TAT for P2=16
P3 P2 P1
TAT for P3=4
0 4 16 40 So, ATAT=TAT for (P1+P2+P3)/3=
60/3=20 MS
• Priority scheduling: it can be either preemptive or non-preemptive. A priority is associated with each process,
and the CPU is allocated to the process with the highest priority, while the priority equals, the processes are
scheduled on an FCFS basis. Zero is the highest priority. Following are the simple example of this scheduling:
Pr_ss Priority B_time
P1 0 24 MS WT for P1=0
P2 1 12 MS WT for P2=24
P3 2 4 MS WT for P3=36, So, AWT=WT for (P1+P2+P3)/3=60/3=
n
Sol : Based on the PS method we can create the 20ms
following Gantt chart: TAT for P1=24
24 12 4 TAT for P2=36
TAT for P3=40, So, ATAT=TAT for (P1+P2+P3)/3=
P1 P2 P3 100/3=33.33 MS
0 24 36 40
• Round Robin schedule: it is specially designed for time-sharing systems. It is similar to the FCFS scheduling but
preemption is needed to switch between processes. The smallest unit of time called slice/quantum is used to switch
the CPU from one task to another. So a cycle can be formed to complete the task in different attempts. Following
are the simple example of this scheduling:
Process B_time
P1 24 MS P1 P2 P3 P1 P2 P1 P2 P1 P1
P2 12 MS 0 5 10 14 19 24 29 31 36 40
P3 4 MS
Soln,
Based on the RR method we can create the following Gantt chart, with 5 MS of time slice:
WT for P1=0+14+24+31=69
WT for P2=5+19+29=53
WT for P3=10
So, AWT= WT for (P1+P2+P3)/3= 32/3=44 MS

TAT for P1=40


TAT for P2=31
TAT for P3=14
So, ATAT= TAT for (P1+P2+P3)/3= 85/3=28.33

• Multilevel queue scheduling: allows different algorithms to be used for various classes of processes. The most
common is the foreground/interactive queue which uses RR scheduling and the background batch queue which
uses FCFS scheduling but the foreground has the highest priority. So each queue has its scheduling mechanism. In
addition, there must be a schedule between the queues which is commonly implemented as fixed-priority
preemptive scheduling. Following is the block diagram of this:
• Multilevel feedback queue scheduling: in multilevel queue scheduling, processes do not move between the
queues but in multilevel feedback queue scheduling, however, allows a process to move between the queues. If a
process uses too much CPU time, it will be moved to a lower-priority queue. Similarly, a process that waits too long
in a lower priority queue may be moved to a higher-priority queue. In this fashion, the processes are executed from
the different queues by using different scheduling algorithms.
Master processes (P1)

Slave processes (P2)

Scheduling Algorithm (P1+P2 = results)

Multi level feedback queue scheduling


Deadlocks
In a multiprogramming environment, several processes may compete for a finite number of resources. A process
requests resources, if the resources are not available at that time; the process enters a wait state. It may happen
that the waiting process will never again change its state because the resources they have requested are held by
other waiting processes. This situation is known as deadlock.

1.1 Deadlock characterization:


A deadlock is a situation in which the CPU can not respond to the processes. In this situation, the utilization of the
CPU can be either 0% or 100%. So a deadlock situation can arise if the following four conditions hold simultaneously
in a system i.e. if an operating system could not manage/maintain one of the following conditions the system
automatically enters into the deadlock situation which is the deadlock characteristics or necessary conditions for
the deadlocks.
▪ Mutual exclusion:
At least one resource must be held in a non-sharable mode; i.e. only one process at a time can use the resource. If
another process requests that resource, the requesting process must be delayed until the resource has been
released. So, other processes have to wait in a ready queue/waiting queue until and unless the previous process will
not complete its full execution.
▪ Hold and wait:
A process must be holding at least one resource and waiting to acquire additional resources that are currently being
held by another process. So, to send the request for the extra resources for executing a particular process, it must
collect the minimum resources first.
▪ Circular wait:
There are a set of processes that wants to use the resources that are held by the other process i.e. P0 is waiting for
a resource that is held by P1, P1 is waiting for a resource that is held by P2, P2 is waiting for a resource that is held
by P3 and so on. It means Pn is the process that is requested the resource and that resource is held by any other
process.
▪ No preemption:
Resources cannot be preempted i.e. a resource can be released only voluntarily by the process holding it after that
process has completed its task. So without completing its full execution we can not preempt the resources from
there.

1.2 Methods for handling deadlocks:


Principally there are three different methods for handling deadlocks. They are:
▪ A protocol is used to prevent or avoid deadlocks, which ensures the system never enters into the deadlock
state.
▪ Once the system enters into the deadlocks state, we should detect it and recover the data and system from the
deadlock successfully.
▪ Uses such types of an operating systems which never entered into a deadlock such as Linux, UNIX, etc. So ignore
the problem altogether and pretend that deadlocks never occur in the system.

To ensure that the deadlocks never occur in a system, we have to use either deadlock prevention or a deadlock
avoidance scheme.

On the other hand, if a system doesn’t ensure that a deadlock will never occur we need to provide an algorithm that
examines the state of the system to determine whether a deadlock has occurred and an algorithm to recover from
the deadlock. Therefore we need to use a deadlock detection and deadlock recovery scheme.

(a). Deadlock prevention:


Deadlock prevention is a set of methods for ensuring that at least one of the necessary conditions can not hold. By
ensuring that at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock. These
methods prevent deadlocks by constraining how requests for resources can be made i.e. how the resources will be
allocated to the particular process for execution. So following are the three different ways to prevent our system
entered into a deadlock condition.
▪ Every process must request all its necessary resources at once and not proceed with the execution without
getting/collecting full resources.
▪ If any process holds certain resources, they can’t request another one without realizing it. After releasing that
one they have to send the request at a time/combined.
▪ If there are multiple instances of the resource on a system, only one can use the single process i.e. that process
can’t send the request to that another instance of the same resources.

But we have to analyze the following four different necessary conditions of the deadlock in terms of deadlock
prevention. That ensures the system never occurs a deadlock.

▪ Mutual exclusion:
In the system, if we have sharable resources there are no chances to occur deadlock because a process never needs
to wait for the shareable resource. But in the case of non-sharable resources, we need to use this concept i.e. at
least one process can use this resource at a time and others must wait in a job pool. Read-only files are a good
example of a sharable resource and the printer is an example of a non-sharable resource.
▪ Hold and wait:
According to this concept, whenever a process requests a resource, it doesn’t hold any other resources. It means a
process allows sending a request for the process only when the process has none i.e. it must release all the
resources that are currently allocated before it can request any additional resources. We need to face the following
disadvantages to using such types of protocol. They are:
(a). Resource utilization: The utilization of the resource may be reduced/low since many of the resources may be
allocated but unused for a long period.
(b). Starvation: A process that needs generally usable resources may have to wait indefinitely because at least one
of the resources that it needs is always allocated to some other process.
▪ No preemption:
No preemption condition is that there is no preemption of resources that have already been allocated. In this, if a
process requests some resources, firstly we need to check whether they are available or not. If they are available,
allocate them but if they are not available, we need to check whether they are allocated to some other process that
is waiting for the additional resources or not.

If so, we preempt the desired resources from the waiting process and allocate them to the requesting process. But
if the resources are not either available or held by a waiting process, the requesting process must wait in a ready
queue/job pool. During this waiting period, some of its resources may be preempted if other process requests
them.

▪ Circular wait:
According to this concept, a process holds at least one resource being requested by the next process and so on. So
we need to break the circular chain of the processes as well as the resources to prevent the deadlock.

(b). Deadlock avoidance:


By applying different preventive measures, we can prevent the deadlock in our system but there is a chance for low
device utilization and reduced system throughput. For this purpose deadlock avoidance is an alternative
mechanism. According to these concepts, the system must provide additional information about how resources are
to be requested. It is the simplest and most useful model. It requires that each process declare the maximum
number of resources of each type that it may need. It means the operating system provides advanced additional
information about the process and the resources i.e. which resources are needed for completing the particular task.

So, to display proper information about each process about the maximum number of resources of each type that
may be requested. It is possible to construct an algorithm that ensures the system will never enter a deadlock state
which defines the deadlock avoidance approach i.e. algorithm.
A deadlock avoidance algorithm dynamically examines the resource-allocation state to ensure that it can never be a
circular wait condition. The resource allocation state is defined by the number of available and allocated resources
and the maximum demands of the processes. For this purpose, we need to examine the state of the process.
Following are the process state:
(a). Safe state: A state is safe if the system can allocate resources to each process. So a safe state is not a deadlock
state.
(b). Unsafe state: Whenever a system can not provide the necessary resources the process that processes fall into
an unsafe state. So a deadlock state is an unsafe state but not all unsafe states are deadlock i.e. unsafe state may
lead to a deadlock. In this, the operating system can’t prevent processes from requesting resources such that a
deadlock occurs.

(c). Deadlock detection:


After applying different deadlock prevention and avoidance mechanism if we can not ensure that our system will
not be entered into a deadlock situation we need to implement deadlock detection and the recovery
scheme/algorithm. Indeed the deadlocks occur in the system so we need to find out where is the deadlock and
under which circumstances the deadlock arises in the system.

So, we can not separate the deadlock detection and the recovery system. In this situation, we need to implement
the following scheme to detect and recover the system from the deadlock.
▪ Apply the deadlock detecting algorithm to determine the state and the condition for the deadlock and find
out where is the deadlock occur.
▪ Apply an algorithm to recover our system from the deadlock.
So, deadlock detection algorithms have to use under the following situation.
▪ If all resources have a single instance, we need to define an algorithm that uses a variant of the resource-
allocation graph.
▪ If a resource has several instances, then an algorithm describes the next applicable processes.
(d). Recovery from deadlock:
Indeed a deadlock occurs in a system we need to implement a deadlock detection algorithm to find out the
deadlock and so on. But our main motive is to recover the system from the deadlock. We can use a different
scheme to do so. By applying manual as well as automatic techniques we can recover our data successfully.

To do this automatically we need to implement some precautions during the installation of an operating system,
then only we can recover more than 80% of our information after recovery from the deadlock otherwise we can't
achieve such an amount of our data. This is done manually only. Following are the two different manual ways to
recover our system from the deadlock.

(a). Process termination:


According to this concept, we need to terminate abnormally (aborted) the processes which are responsible for
entering our system into a deadlock. So we use one of the following methods to eliminate deadlocks by aborting a
process but aborting a process may not be easy because it is not the right solution i.e. economic one.
▪ Abort all deadlocked processes until and unless the deadlock cycle is not broken but at a great expanse because
such processes take a long time to compute and so on.
▪ Abort one process at a time until the deadlock cycle is not eliminated.

(b). Resource preemption:


To eliminate deadlocks using resource preemption methods, we need to preempt some resources from the
processes and allocate such resources to other processes until the deadlock cycle is not broken. The following three
issues are needed to be addressed to recover our system from the deadlock by using this resource preempted
method.
(i). Selecting a victim: To achieve cost-effectiveness and more data, we need to select which resources and which
processes are to be preempted? So we must check the permission about the processes as well as resources
preemption.
(ii). Rollback: After preempting the resources from the processes it can't continue its execution and it became an
unsafe state. At that time we need to restart the process execution.
(iii). Starvation: According to this concept we need to ensure and preempt the resources only when the processes
will not demand such resources later.

Memory management
In a uni-programming environment, the system is divided into two parts: one for operating systems and another for
the programs currently being executed. On the other hand, in a multiprogramming system, the user's parts of the
memory are further being subdivided to accommodate processes i.e. Multi-processes. This is done by the operating
system dynamically which is known as storage/memory management.

To improve its response to its users, the computer must keep several processes in memory. The selection of a
memory management scheme for a specific system depends on many factors, especially on the hardware
configurations of the system.

As we know, memory is a large array of words or bytes, each with its address. The CPU fetches instructions from
memory according to the value of the program counter. These instructions may cause additional loading from and
storing to a specific memory address.

1.1 Logical Vs physical address space:

An address generated by the CPU is commonly referred to as a logical address, whereas an address seen by the
memory unit is commonly referred to as a physical address. It means that the user never sees the real physical
addresses. The compile-time and load time address binding schemes result in an environment where the logical and
physical addresses are the same. However the execution time address-binding scheme results in an environment
where the logical and physical address differs.
The set of all logical addresses generated by a program is referred to as a logical address space; the set of all
physical addresses corresponding to these logical addresses is referred to as a physical address space. Thus in
execution time, the address binding scheme logical and physical address spaces differ. The runtime mapping from
virtual to physical addresses is done by the memory-management unit (MMU), which is a hardware device. The
memory mapping hardware converts logical addresses into a physical addresses and vice versa.

1.2 Swapping:
A process needs to be in the memory to be executed. A process however can be swapped temporarily out of
memory to a backing store and then brought back into the memory for continued execution. A variant of this
swapping policy is used for priority-based scheduling algorithms. If a high-priority process arrives and wants service,
the memory manager can swap out the lower priority process so that it can load and execute the higher priority
process. When the higher priority process finishes, the lower priority process can be swapped back in, and
continued this variant of swapping is known as roll-out, roll-in.
Normally, a process that will swap out will be swapped back into the same location. Swapping requires a backing
store. The backing store is commonly a fast risk. It must be large enough to accommodate copies of all memory
images for all users and must provide direct access to the memory images. The system maintains a ready queue
consisting of all processes whose memory images are on the backing store or in memory and are ready to run.

1.3 Contiguous allocation


In this, each program has to occupy a single contiguous block of storage location. In non-contiguous storage
allocation, a program is divided into several blocks or segments that may be placed throughout the main memory in
pieces. Not necessarily adjacent to one another. It is more difficult to control non-contiguous storage allocation.
The benefit is that if the main storage has many small holes available instead of a single large hole, then the
operating system can often load and execute a program that otherwise needs to wait.
As we know programs are limited in size to the amount of main storage but it is possible to run programs larger
than the main storage using the concept of overlays. If a particular program section is not needed for the duration
of program execution when another section of the program may be brought in from the secondary storage to
occupy the storage used by the program that is no longer needed. Overlays give the programmer to extend limited
main storage but manual overlays structure can be difficult to modify.

1.4 Paging:
The problem of external fragmentation has two solutions. The first one is compaction, which changes the allocation
of memory to make free space contiguous and hence useful to users' programs. Another one is paging, which
permits a program’s memory to be non-contiguous, allowing a program to be allocated to physical memory
wherever it is available. Physical memory is broken into fixed-sized blocks called frames.

Logical memory is broken into blocks of the same size called pages. In this, every address is divided into two pates
i.e. Page number and page offset, where, the page number is used as an index into a page table and page offset is a
displacement with a page at which the reference address is loaded. It means every address generated by the CPU is
divided into two parts. They are:
# Page number (P) # Page offset (D)
In this, the page table contains the base address of each page in physical memory. This base address is combined
with the page offset to define the physical memory address. In the figure “f” is denoted to the base address.
A special memory management unit (MMU) performs the address translation i.e. from virtual (logical) to physical.
f
CPU P D F D
P
f
Logical Physical
address address
Page table Disk
Block diagram of Paging
1.5 Segmentation:
An alternative way is in which, the user program and its associated data are divided into many segments. In this
case the program number and an offset. It is not required that all segments of all programs be of the same length.
As with paging a logical address using segmentation consists of two parts:
-Segment number -Segment offset.
Because of the use of unequal size to dynamic partition, the difference compared with dynamic partition is that
with segmentation. A program may occupy more than one partition and those partitions need not be contagious.

Segmentation eliminates internal fragmentation. But like dynamic fragmentation, however, because a process is
broken up into many small pieces the external should be less. Paging is invisible to the program which as a
segmentation operating system is usually visible to the programmer.

1.5.1 Characteristics of the segmentation:


Following are some characteristics of the segmentation.
a. The main memory is not partitioning.
b. Program segments are specified by the programmer to the compiler i.e. the decision is made by the
programmer.
c. External fragmentation is present in the segmentation.
d. An operating system must maintain a segment for each process by showing the limit and base.
e. An operating system must maintain a list of free holes or partitions in the main memory.
f. All the segments of a process must be in the main memory for the process to run unless overlays are used.

1.5.2 Combined approach of segmentation and paging:


Both segmentation and paging scheme is combined to improve their efficiency. In a combined system, a user’s
address space is broken up into many segments at the discretion of the programmer. Each segment is in turn
broken up into many fixed-size pages, which are equal in length to the main memory frame. If a segment is less
than one page from the system's point of view, the segment offset is viewed as a page number and page offset for a
page within the specified segments.

It suggests structure support to a combination of paging and segmentation. Associated with each process in a
segment table and many pages table one per process segment. When a particular process is running a register holds
the starting address of the hr segment table for that process.

Presented with a virtual address the processor uses the segment number portion to index into the process segment
table to find the page table for the virtual address is used to index the page table and look up the corresponding
frame number. This is combined with the offset portion of the virtual address to produce the desired real address.

Virtual Memory
The key to the virtual storage concept is disassociating the address referenced in a running process from the
addresses available in primary storage. The addresses referenced by a running process are called virtual addresses.
The addresses available in primary storage are called real addresses. Even though processes reference only virtual
addresses they must be mapped into real addresses or – process executes.

Dynamic address translation (DAI) mechanisms convert virtual addresses to real addresses as a process executes.
The system exhibits the property that the address contiguous in a process virtual address space need not be
contiguous in real storage. This is called artificial contiguity.

1.1 Demand Paging:


It is the conventional wisdom that a process page should be loaded on demand. No page should be brought from
secondary to primary storage until a running process explicitly references it. There are several reasons for the
appeal of this strategy. They are:
▪ Computability results: Specifically, the haul ting problem, tells us that the path of executing a program will take
can’t be accurately predicted. Therefore any attempt to preload pages in anticipation of their use might result,
in the wrong page being loaded.
▪ Demand paging: It guarantees that the only pages brought to main storage are those needed by the processes.
▪ Pure demand paging: There is a possibility that the management scheme could execute with no page fault i.e. It
never brings a page into memory until it is required. This is known as pure demand paging.

1.1.1 Performance of Demand paging:


Demand paging can have a significant effect on the performance of a computer system. If there are no page faults
the effective access time will be equal to the normal memory access time. Most computer system now ranges from
10 to 200 mono sec.

If a page fault occurs, the time faults as an address to effective access time are then effective access time = (1-P) x
ma + p x page fault time where, Ma = memory address, P is a probability of a page fault (O≤ P ≤ 1), we would accept
P to be close to zero i.e. with few page faults.

There are three major components of the page fault services time.
▪ Time is taken to swap in the page ▪ Time is taken to restart the process.
▪ Time is taken to service the page fault interrupt.

1.2 Page replacement:


Every operating system has its unique replacement scheme. Any page replacement algorithm should aim to attain
the lowest page fault rate. Assumption: running it on a particular string of memory response and computing the
number of page faults evaluate every algorithm. The random number can generate a reference string artificially by
the address of each memory reference.
1.2.1 Page replacement algorithm
There are many different page replacement algorithms. Probably every operating system has its unique
replacement scheme. We have to select those algorithm schemes which one can perform this job with the lowest
page fault rate. We evaluate an algorithm by running it on a particular string of memory references and computing
the number of page faults. The string of memory references is known as a reference string. Mainly they are three
different types of replacement algorithms. They are

i) FIFO algorithm:
It is the simplest algorithm associated with each page the time when that page was brought into memory. When a
page must be replaced, the oldest page is chosen. FIFO queue is created to hold all memory pages. The page is
replaced at the head of the queue. When a page is brought into memory, we insert it at the tail of the queue. To
illustrate the page replacement algorithms we shall use the following reference string for memory with three
frames. Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Page fault: 3 frames
Sol.
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2 4 4 4 0 0 0 7 7 7
0 0 0 3 3 3 2 2 2 1 1 1 0 0
1 1 1 0 0 0 3 3 3 2 2 2 1

ii) Optimal algorithm:


An optimal page replacement algorithm has the lowest page-fault rate of all algorithms. An optimal page
replacement algorithm exists and has been called OPT or MIN. So we can simply say that replace the page that will
not be used for the longest period. Consider the following reference string i.e. for memory with 3 frames. Reference
string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Page fault: 3 frames
Sol.
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2 2 2 7
0 0 0 0 4 0 0 40

1 1 3 33 33 21 21
0 0 3
iii) LRU algorithm:
If we use the recent past as an approximation of the near future, then we will replace the page that has not been
used for the longest period. This approach is the least recently used algorithm. LRU replacement associates with
each page the time of the page’s last use. When a page must be replaced LRU chooses that page that has not been
used for the longest period. Consider the following reference string concerning a memory with three frames.
Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Page fault: 3 frames
Sol.
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 4 4 4 0 1 1 1
2 2 2 2 2 2 4
0 0 0 0 0 0 3 3 3 0 0
4 4 0 0 2 2 2
1 1 3 33 23 24 23 2 2 7
3 33 3 0 0 3
1.3 Frame allocations 0
A different problem arises when demand paging is combined with multiprogramming. Multiprogramming puts two
or more processes in memory at the same time. The problem is to allocate the fixed amount of free memory among
the various process. We can’t allocate more than the total number of available frames. There must also be a
minimum number of frames, which can be allocated for every process. Now we decide that the minimum number
of frames per user process should define by the architecture while the maximum number is defined by the amount
of available physical memory.
Other important factors in the way that frames are allocated to the various processes in page replacement. With
multiply processes computing for frames, we can classify page replacement algorithms into two different
categories. They are global replacement and local replacement.

# Global replacement allows a process a select a replacement frame from the set of all frames even if that frame is
currently allocated to some other processes; one process can take a frame from another.
# Local replacement requires that each process selects from only its own set of allocated frames.

1.4 Thrashing:
Any process, which doesn’t have enough frames, will quickly lead to page fault. If there is a maximum number of
page faults, it will decrease the CPU performance, because the CPU wills do not do the process execution i.e. CPU is
busy with page replacement and demand paging rather than the compilation. At this point, it must replace some
pages however, since all pages are in active use, it must replace a page that will be needed again right away. Due to
this a page fault arises again, again and again. This very high paging activity is known as thrashing i.e. When CPU
utilization is decreased; we have to face the problem of thrashing. Following is the block diagram of thrashing.

A process is threshing if it is spending more time paging than executing. So thrashing leads to poor performance of
the system. The CPU scheduler seeps the decreasing CPU utilization & increases the degree of multiprogramming as
a request. Her new process tries to get started by taking pages from running processes, causing more page faults &
a longer queue for the paging device. As a result, CPU utilization drop even further, & the CPU scheduler tries to
increase the degree of multiprogramming even more. That is, the page fault rate increased & thrashing occur
serially. No work is getting done because the processes are spending their max time replacing the page rather than
the proper execution. Following are the solution to this:
▪ Locating model of program execution.
▪ Working set model of program execution.
▪ Page fault frequency strategies.
1.5. Other considerations:
The selection of a replacement algorithm &allocation policy is the major decisions to make for a paging system.
There is many other consideration as well. Some of them are:
1). Pre paging 2). Page size

1.6 Demand segmentation:


As we know, there is a limited no of resources in the systems. Although demand paging is generally considered the
most efficient virtual memory system a significant amount of hardware is required to implement it. When this
hardware is lacking less efficient means are sometimes devised to provide virtual memory. A space in point is
demand segmentation.

You might also like