Operating System Notes
Operating System Notes
System (OS)
What do you mean by memory management?
Memory is the important part of the computer that is used to store the data. Its
management is critical to the computer system because the amount of main
memory available in a computer system is very limited. At any time, many
processes are competing for it. Moreover, to increase performance, several
processes are executed simultaneously. For this, we must keep several
processes in the main memory, so it is even more important to manage them
effectively.
Multiple Partitioning:
The single Contiguous memory management scheme is inefficient as it limits
computers to execute only one program at a time resulting in wastage in
memory space and CPU time. The problem of inefficient CPU use can be
overcome using multiprogramming that allows more than one program to run
concurrently. To switch between two processes, the operating systems need to
load both processes into the main memory. The operating system needs to
divide the available main memory into multiple parts to load multiple
processes into the main memory. Thus multiple processes can reside in the
main memory simultaneously.
o Fixed Partitioning
o Dynamic Partitioning
Fixed Partitioning
The main memory is divided into several fixed-sized partitions in a fixed
partition memory management scheme or static partitioning. These partitions
can be of the same size or different sizes. Each partition can hold a single
process. The number of partitions determines the degree of
multiprogramming, i.e., the maximum number of processes in memory. These
partitions are made at the time of system generation and remain fixed after
that.
o Simple to implement.
o Easy to manage and design.
Disadvantages of Fixed Partitioning memory management schemes:
Dynamic Partitioning
The dynamic partitioning was designed to overcome the problems of a fixed
partitioning scheme. In a dynamic partitioning scheme, each process occupies
only as much memory as they require when loaded for processing. Requested
processes are allocated memory until the entire physical memory is exhausted
or the remaining space is insufficient to hold the requesting process. In this
scheme the partitions used are of variable size, and the number of partitions is
not defined at the system generation time.
o Simple to implement.
o Easy to manage and design.
Disadvantages of Dynamic Partitioning memory management schemes:
What is paging?
Paging is a technique that eliminates the requirements of contiguous
allocation of main memory. In this, the main memory is divided into fixed-size
blocks of physical memory called frames. The size of a frame should be kept the
same as that of a page to maximize the main memory and avoid external
fragmentation.
Advantages of paging:
What is Segmentation?
Segmentation is a technique that eliminates the requirements of contiguous
allocation of main memory. In this, the main memory is divided into variable-
size blocks of physical memory called segments. It is based on the way the
programmer follows to structure their programs. With segmented memory
allocation, each job is divided into several segments of different sizes, one for
each module. Functions, subroutines, stack, array, etc., are examples of such
modules.
Next
Memory management is the functionality of an operating system which
handles or manages primary memory and moves processes back and forth
between main memory and disk during execution. Memory management
keeps track of each and every memory location, regardless of either it is
allocated to some process or it is free. It checks how much memory is to be
allocated to processes. It decides which process will get memory at what
time. It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
This tutorial will teach you basic concepts related to Memory Management.
The operating system takes care of mapping the logical addresses to physical
addresses at the time of memory allocation to the program. There are three
types of addresses used in a program before and after memory is allocated −
1 Symbolic addresses
The addresses used in a source code. The variable names, constants, and instruction
labels are the basic elements of the symbolic address space.
Relative addresses
2 At the time of compilation, a compiler converts symbolic addresses into relative
addresses.
Physical addresses
3 The loader generates these addresses at the time when a program is loaded into main
memory.
Virtual and physical addresses are the same in compile-time and load-time
address-binding schemes. Virtual and physical addresses differ in execution-
time address-binding scheme.
The runtime mapping from virtual to physical address is done by the memory
management unit (MMU) which is a hardware device. MMU uses following
mechanism to convert virtual address to physical address.
Swapping
Swapping is a mechanism in which a process can be swapped temporarily out
of main memory (or move) to secondary storage (disk) and make that
memory available to other processes. At some later time, the system swaps
back the process from the secondary storage to main memory.
Let us assume that the user process is of size 2048KB and on a standard
hard disk where swapping will take place has a data transfer rate around 1
MB per second. The actual transfer of the 1000K process to or from memory
will take
Now considering in and out time, it will take complete 4000 milliseconds plus
other overhead where the process competes to regain main memory.
Memory Allocation
Main memory usually has two partitions −
Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized
2 partitions where each partition should contain only one process. When a partition is
free, a process is selected from the input queue and is loaded into the free partition.
When the process terminates, the partition becomes available for another process.
Fragmentation
As processes are loaded and removed from memory, the free memory space
is broken into little pieces. It happens after sometimes that processes cannot
be allocated to memory blocks considering their small size and memory
blocks remains unused. This problem is known as Fragmentation.
External fragmentation
1 Total memory space is enough to satisfy a request or to reside a process in it, but it is
not contiguous, so it cannot be used.
Internal fragmentation
2 Memory block assigned to process is bigger. Some portion of memory is left unused,
as it cannot be used by another process.
The following diagram shows how fragmentation can cause waste of memory
and a compaction technique can be used to create more free memory out of
fragmented memory −
External fragmentation can be reduced by compaction or shuffle memory
contents to place all free memory together in one large block. To make
compaction feasible, relocation should be dynamic.
Paging
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 that's set up to emulate the computer's RAM. Paging
technique plays an important role in implementing virtual memory.
A data structure called page map table is used to keep track of the relation
between a page of a process to a frame in physical memory.
When the system allocates a frame to any page, it translates this logical
address into a physical address and create entry into the page table to be
used throughout execution of the program.
This process continues during the whole execution of the program where the
OS keeps removing idle pages from the main memory and write them onto
the secondary memory and bring them back when required by the program.
Print Page
Operating System - Virtual Memory
Next
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.
• 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.
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 −
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.
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 p will 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
File
A file is a named collection of related information that is recorded on
secondary storage such as magnetic disks, magnetic tapes and optical disks.
In general, a file is a sequence of bits, bytes, lines or records whose meaning
is defined by the files creator and user.
File Structure
A File Structure should be according to a required format that the operating
system can understand.
File Type
File type refers to the ability of the operating system to distinguish different
types of file such as text files source files and binary files etc. Many operating
systems support many types of files. Operating system like MS-DOS and
UNIX have the following types of files −
Ordinary files
• These are the files that contain user information.
• These may have text, databases or executable program.
• The user can apply various operations on such files like add, modify,
delete or even remove the entire file.
Directory files
• These files contain list of file names and other information related to
these files.
Special files
• These files are also known as device files.
• These files represent physical device like disks, terminals, printers,
networks, tape drive etc.
• Sequential access
• Direct/Random access
• Indexed sequential access
Sequential access
A sequential access is that in which the records are accessed in some
sequence, i.e., the information in the file is processed in order, one record
after the other. This access method is the most primitive one. Example:
Compilers usually access files in this fashion.
Direct/Random access
• Random access file organization provides, accessing the records directly.
• Each record has its own address on the file with by the help of which it
can be directly accessed for reading or writing.
• The records need not be in any sequence within the file and they need
not be in adjacent locations on the storage medium.
Space Allocation
Files are allocated disk spaces by operating system. Operating systems
deploy following three main ways to allocate disk space to files.
• Contiguous Allocation
• Linked Allocation
• Indexed Allocation
Contiguous Allocation
• Each file occupies a contiguous address space on disk.
• Assigned disk address is in linear order.
• Easy to implement.
• External fragmentation is a major issue with this type of allocation
technique.
Linked Allocation
• Each file carries a list of links to disk blocks.
• Directory contains link / pointer to first block of a file.
• No external fragmentation
• Effectively used in sequential access file.
• Inefficient in case of direct access file.
Indexed Allocation
• Provides solutions to problems of contiguous and linked allocation.
• A index block is created having all pointers to files.
• Each file has its own index block which stores the addresses of disk space
occupied by the file.
• Directory contains the addresses of index blocks of files.
Secondary Input and Output
One of the important jobs of an Operating System is to manage various I/O devices including
mouse, keyboards, touch pad, disk drives, display adapters, USB devices, Bit-mapped screen,
LED, Analog-to-digital converter, On/off switch, network connections, audio I/O, printers etc.
An I/O system is required to take an application I/O request and send it to the physical device,
then take whatever response comes back from the device and send it to the application.
Block devices − A block device is one with which the driver communicates by sending entire
blocks of data. For example, Hard disks, USB cameras, Disk-On-Key etc.
Character devices − A character device is one with which the driver communicates by sending
and receiving single characters (bytes, octets). For example, serial ports, parallel ports, sounds
cards etc.
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.
Disk structure
• Modern magnetic disk drives are addressed as large one-dimensional
arrays of logical blocks, where the logical block is the smallest unit of
transfer.
• The size of a logical block is usually 512 bytes, although some disks can
be low-level formatted to have a different logical block size, such as
1,024 bytes.
• The one-dimensional array of logical blocks is mapped onto the sectors
of the disk sequentially.
• Sector 0 is the first sector of the first track on the outermost cylinder.
• The mapping proceeds in order through that track, then through the rest
of the tracks in that cylinder, and then through the rest of the cylinders
from outermost to innermost.
• The number of sectors per track has been increasing as disk technology
improves, and the outer zone of a disk usually has several hundred
sectors per track. Similarly, the number of cylinders per disk has been
increasing; large disks have tens of thousands of cylinders.
In this article, we will explore the different types of disk scheduling algorithms and their
functions. By understanding and implementing these algorithms, we can optimize system
performance and ensure faster data retrieval.
• Hard drives are one of the slowest parts of the computer system and thus need to be
accessed in an efficient manner.
• Rotational Latency: Rotational Latency is the time taken by the desired sector of the
disk to rotate into a position so that it can access the read/write heads. So the disk
scheduling algorithm that gives minimum rotational latency is better.
• Transfer Time: Transfer time is the time to transfer the data. It depends on the
rotating speed of the disk and the number of bytes to be transferred.
• Disk Response Time: Response Time is the average time spent by a request waiting
to perform its I/O operation. The average Response time is the response time of all
requests. Variance Response Time is the measure of how individual requests are
serviced with respect to average response time. So the disk scheduling algorithm that
gives minimum variance response time is better.
• Maximize Throughput
• Minimize Latency
• Fairness
FCFS is the simplest of all Disk Scheduling Algorithms. In FCFS, the requests are addressed
in the order they arrive in the disk queue. Let us understand this with the help of an example.
Example:
So, total overhead movement (total distance covered by the disk arm) =
(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16) =642
Advantages of FCFS
• No indefinite postponement
Disadvantages of FCFS
In SSTF (Shortest Seek Time First), requests having the shortest seek time are executed first.
So, the seek time of every request is calculated in advance in the queue and then they are
scheduled according to their calculated seek time. As a result, the request near the disk arm
will get executed first. SSTF is certainly an improvement over FCFS as it decreases the average
response time and increases the throughput of the system. Let us understand this with the help
of an example.
Example:
So,
• Can cause Starvation for a request if it has a higher seek time as compared to
incoming requests
• The high variance of response time as SSTF favors only some requests
3. SCAN
In the SCAN algorithm the disk arm moves in a particular direction and services the requests
coming in its path and after reaching the end of the disk, it reverses its direction and again
services the request arriving in its path. So, this algorithm works as an elevator and is hence
also known as an elevator algorithm. As a result, the requests at the midrange are serviced
more and those arriving behind the disk arm will have to wait.
Example:
SCAN Algorithm
Therefore, the total overhead movement (total distance covered by the disk arm) is calculated
as
• High throughput
• Long waiting time for requests for locations just visited by disk arm
4. C-SCAN
In the SCAN algorithm, the disk arm again scans the path that has been scanned, after reversing
its direction. So, it may be possible that too many requests are waiting at the other end or there
may be zero or few requests pending at the scanned area.
These situations are avoided in the CSCAN algorithm in which the disk arm instead of reversing
its direction goes to the other end of the disk and starts servicing the requests from there. So,
the disk arm moves in a circular fashion and this algorithm is also similar to the SCAN
algorithm hence it is known as C-SCAN (Circular SCAN).
Example:
Circular SCAN
Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write arm is
at 50, and it is also given that the disk arm should move “towards the larger value”.
So, the total overhead movement (total distance covered by the disk arm) is calculated as:
5. LOOK
LOOK Algorithm is similar to the SCAN disk scheduling algorithm except for the difference
that the disk arm in spite of going to the end of the disk goes only to the last request to be
serviced in front of the head and then reverses its direction from there only. Thus it prevents
the extra delay which occurred due to unnecessary traversal to the end of the disk.
Example:
LOOK Algorithm
So, the total overhead movement (total distance covered by the disk arm) is calculated as:
As LOOK is similar to the SCAN algorithm, in a similar way, C-LOOK is similar to the
CSCAN disk scheduling algorithm. In CLOOK, the disk arm in spite of going to the end goes
only to the last request to be serviced in front of the head and then from there goes to the other
end’s last request. Thus, it also prevents the extra delay which occurred due to unnecessary
traversal to the end of the disk.
Example:
C-LOOK
So, the total overhead movement (total distance covered by the disk arm) is calculated as
It stands for Random Scheduling and just like its name it is natural. It is used in situations
where scheduling involves random attributes such as random processing time, random due
dates, random weights, and stochastic machine breakdowns this algorithm sits perfectly.
Which is why it is usually used for analysis and simulation.
Here are some of the advantages of the Last In First Out Algorithm.
• Can seem a little unfair to other requests and if new requests keep coming in, it cause
starvation to the old and existing ones.
9. N-STEP SCAN
It is also known as the N-STEP LOOK algorithm. In this, a buffer is created for N requests.
All requests belonging to a buffer will be serviced in one go. Also once the buffer is full no
new requests are kept in this buffer and are sent to another one. Now, when these N requests
are serviced, the time comes for another top N request and this way all get requests to get a
guaranteed service
10. F-SCAN
This algorithm uses two sub-queues. During the scan, all requests in the first queue are
serviced and the new incoming requests are added to the second queue. All new requests are
kept on halt until the existing requests in the first queue are serviced.
Advantages of F-SCAN
Each algorithm is unique in its own way. Overall Performance depends on the number and
type of requests.
•
•
In an Operating System, Client Server Communication refers to the exchange of data and Services
among multiple machines or processes. In Client client-server communication System one process or
machine acts as a client requesting a service or data, and Another machine or process acts like a
server for providing those Services or Data to the client machine. This Communication model is
widely used for exchanging data among various computing environments like Distributed Systems,
Internet Applications, and Networking Application communication. The communication between
Server and Client takes place with different Protocols and mechanisms.
1. Sockets Mechanism
3. Message Passing
4. Inter-process Communication
Sockets Mechanism
The Sockets are the End Points of Communication between two machines. They provide a way for
processes to communicate with each other, either on the same on machine or over through Internet
also possible. The Sockets enable the communication connection between Serthe er and the client to
transfer data in a bidirectional way.
Remote Procedure Call is a Protocol. A Protocol is set of Instructions. It allows a client to execute a
procedure call on remote server, as if it is local procedure call. PRC is commonly used in Client Server
communication Architecture. PRC Provide high level of abstraction to the programmer. In This The
client Program issues a procedure call , which is translated into message that is sent over the
network to the Server, The Server execute the call and send back to the Client Machine.
Message Passing
Message Passing is a communication Method. Where the machines communicated with each one by
send and receiving the messages. This approach is commonly used in Parallel and Distributed
Systems, This approach enables data exchange among the System.
The Inter Process Communication also called IPC. It allows communication between processes within
the same Machine. The IPC can enable data sharing and Synchronous between different processes
running concurrently on an operating system. And it includes Sharing Memory, message queues,
semaphores and pipes among others.
Distributed File Systems provide access to files from multiple machines in network. Client can access
and manipulate files stored on Remote Server, Through Standard Interface Example Network File
System and Server Message Block.
When we talk about networks, the first thing that comes to mind is how data transfers from one
device to another. Sharing digital information and resources is a vital part of information technology.
A peer-to-peer (P2P) network connecting devices may improve connectivity and access to shared
assets, allowing your organization to run more efficiently.
When devices are linked together, they share resources without requiring separate server or server
software. To understand the peer-to-peer model, let’s take the example of a torrent. As we already
know, torrent software is used for downloading movies and files. How is this peer-to-peer model
working in this torrent file? Suppose your organization has four personal computers, PC1, PC2, PC3,
and PC4. In PC1, when we use torrent, PC1 checks all devices on the internet running that particular
software that has torrent. As soon as PC1 finds any other PC that is running torrent software, it will
ask for the file it wants to download. Suppose PC2 is running that software and it is nearest to PC1,
so this PC1 asks PC2 to give him that file, and PC1 will download that file. But what if PC2 does not
have that file? Then the data or the query will be forwarded to the next device, PC3. If PC3 has that
file, it will revert to PC1 and give him that file access. This entire process is known as a peer-to-peer
model in networks.
1. Unstructured peer-to-peer model : As the name suggests, devices are connected randomly in
networks in this type of model. This model is easy to build since there is no structure imposed.
However, because it is unstructured, it is hard to discover information.
2. Structured peer-to-peer model: In this model, devices are connected in a specific topology.
Distributed hash tables are commonly used to construct structured networks. The software used to
build a structured peer-to-peer model integrates the network’s virtual layer into a predefined
structure.
3. Hybrid peer-to-peer model: This model is the combination of the peer-to-peer model and the
client-server model. There are numerous types of hybrid networks, and a popular hybrid network
uses a central server to help users locate each other.
Due to its architecture, a peer-to-peer model offers many advantages to its user, including:
1. Easy to maintain: A peer-to-peer model has no server in between their devices. So maintaining
this type of network is very useful and easy to handle.
2. Cost-effective: This model doesn’t require a particular server for a specific device, which reduces
its cost. It does not demand the use of a network operating system or the services of a full-time
System Administrator.
3. Easy file sharing: A strong peer-to-peer model can instantly distribute files over long distances. You
can access your files from anywhere.
4. Adaptability: The peer-to-peer model can simply expand to add new customers. Because of this
advantage, these networks are more adaptable than the client-server model, and its scalability is one
of its most appealing features.
5. Efficiency: Developing a peer-to-peer model enables collaboration amongst devices with different
resources that can benefit the entire system.
1. File sharing: The activity of offering files and allowing others to obtain them over the internet is
known as file sharing. File sharing is based on the peer-to-peer network concept, in which clients’
personal computers are considered peers in the network.
2. Bioinformatics: Peer-to-peer networks have also begun to capture the interest of scientists and
researchers, particularly those working with extensive data, such as bioinformatics. Peer-to-peer
networks can execute huge systems that deal with extensive data.
3. Artificial intelligence: Swarm intelligence (SI) is an artificial intelligence method focused on
observing collective actions in fragmented, self-organized systems. A peer-to-peer network can be
used to develop swarm intelligence, with each peer referring to a single person.
4. Grid computing: Grid computing is a growing computer model that allows for high bandwidth
processing. Grids utilize the resources of several different computers (peers) connected by a network
to solve large-scale calculation problems, usually over the Internet.