0% found this document useful (0 votes)
36 views42 pages

Os Notes

Uploaded by

animeshsingh2207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views42 pages

Os Notes

Uploaded by

animeshsingh2207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

NEED OF CPU SCHEDULING :

1. Maxmimum utiization of CPU.

2. Fare Allocation of CPU.

3. Maximum Throughput.

4. Minimum Turn Around Time. (To minimize the total time taken from process submission to its
completion).

5. Minimum Waiting Time. ( To reduce the amount of time a process spends waiting in the ready
queue).

6. MInimum Response Time.(To provide prompt responses to interactive users).

Throughput measures the number of processes that are completed per unit of time. Higher throughput
means the system is processing tasks efficiently and effectively.

Turnaround time is the sum of the time spent waiting to get into memory, waiting in the ready queue,
executing on the CPU, and doing I/O. Reducing turnaround time improves the overall efficiency and user
experience.

Waiting time is the total time a process spends in the ready queue waiting for CPU access.

Response time is the time from when a request is submitted until the first response is produced.

TYPES OF SCHEDULING ALGORITHM :

FCFS :

Advantage :

1. Easy to implement.

2. Minimizes the chances of process starvation.

Disadvatage :

1. It hs a long wating time.

2. There a chance of the occurence of convoy effect.

The convoy effect happens when a CPU-bound process (a process that requires substantial CPU time) is
placed at the head of the queue. This situation causes all other processes, including shorter or I/O-
bound processes, to wait for the CPU-bound process to complete its execution or reach an I/O
operation.
SJF :

Advantages :

Maximum throughput

Minimum average waiting and turnaround time

Disadvantages :

May suffer with the problem of starvation

It is not implementable because the exact Burst time for a process can't be known in advance.

SRTF :

Advantages :

Reduced waiting time.

Optimal Turn Around time.

Disadvantages :

High Overhead (due to large number of context switching))

problem of starvation.

ROUND ROBIN :

Advantages :

A fair amount of CPU is allocated to each job.

It doesn't depend on the burst time, it can truly be implemented in the system.

Disadvantages :

Low Operating System slicing times will result in decreased CPU output.

Round Robin CPU Scheduling approach takes longer to swap contexts. hence high system overhead.

---------------------------------------------------------------------------------------------------------------------------

Semaphore is the variables which stores the entire wake up calls that are being transferred from
producer to consumer. It is a variable on which read, modify and update happensautomatically in kernel
mode.

NOTE : Semaphores were introdued to get rid of the wastage of wake-up calls.
Counting Semaphore

There are the scenarios in which more than one processes need to execute in critical section
simultaneously. However, counting semaphore can be used when we need to have more than one
process in the critical section at the same time.

In counting semaphore, Mutual exclusion was not provided because we have the set of processes which
required to execute in the critical section simultaneously.

Binary Semaphores

However, Binary Semaphore strictly provides mutual exclusion. Here, instead of having more than 1
slots available in the critical section, we can only have at most 1 process in the critical section. The
semaphore can have only two values, 0 or 1.

Deadlock

A Deadlock is a situation where each of the computer process waits for a resource which is being
assigned to some another process. In this situation, none of the process gets executed since the
resource it needs, is held by some other process which is also waiting for some other resource to be
released.
Necessary conditions for Deadlocks

Mutual Exclusion

A resource can only be shared in mutually exclusive manner. It implies, if two process cannot use the
same resource at the same time.

Hold and Wait

A process waits for some resources while holding another resource at the same time.

No preemption

The process which once scheduled will be executed till the completion. No other process can be
scheduled by the scheduler meanwhile.

Circular Wait

All the processes must be waiting for the resources in a cyclic manner so that the last process is waiting
for the resource which is being held by the first process.

Deadlock Preve.tion :

Spooling

For a device like printer, spooling can work. There is a memory associated with the printer which stores
jobs from each of the process into it. Later, Printer collects all the jobs and print each one of them
according to FCFS. By using this mechanism, the process doesn't have to wait for the printer and it can
continue whatever it was doing. Later, it collects the output when it is produced.
No Preemption

Deadlock arises due to the fact that a process can't be stopped once it starts. However, if we take the
resource away from the process which is causing deadlock then we can prevent deadlock.

This is not a good approach at all since if we take a resource away which is being used by the process
then all the work which it has done till now can become inconsistent.

!(Hold and wait) = !hold or !wait (negation of hold and wait is, either you don't hold or you don't wait)

This can be implemented practically if a process declares all the resources initially. However, this sounds
very practical but can't be done in the computer system because a process can't determine necessary
resources initially.

Process is the set of instructions which are executed by the CPU. Each of the instruction may demand
multiple resources at the multiple times. The need cannot be fixed by the OS

The problem with the approach is:

Practically not possible.

Possibility of getting starved will be increases due to the fact that some process may hold a resource for
a very long time.

Circular Wait

To violate circular wait, we can assign a priority number to each of the resource. A process can't request
for a lesser priority resource. This ensures that not a single process can request a resource which is
being utilized by some other process and no cycle will be formed.
Example:

Suppose there are three processes P1, P2, and P3, and three resources R1 (priority 1), R2 (priority 2),
and R3 (priority 3).

If P1 holds R1 and needs R2, it can directly request R2.

If P2 holds R2 and needs R3, it can request R3.

If P3 holds R3 and needs R1, it cannot directly request R1 as it violates the priority order. P3 must first
release R3 before requesting R1

Deadlock avoidance

In deadlock avoidance, the request for any resource will be granted if the resulting state of the system
doesn't cause deadlock in the system. The state of the system will continuously be checked for safe and
unsafe states.

In order to avoid deadlocks, the process must tell OS, the maximum number of resources a process can
request to complete its execution.

The simplest and most useful approach states that the process should declare the maximum number of
resources of each type it may ever need. The Deadlock avoidance algorithm examines the resource
allocations so that there can never be a circular wait condition.

Safe and Unsafe States

A state of the system is called safe if the system can allocate all the resources requested by all the
processes without entering into deadlock.
If the system cannot fulfill the request of all processes then the state of the system is called unsafe.

The key of Deadlock avoidance approach is when the request is made for resources then the request
must only be approved in the case if the resulting state is also a safe state.

Resource Allocation Graph

The resource allocation graph is the pictorial representation of the state of a system. As its name
suggests, the resource allocation graph is the complete information about all the processes which are
holding some resources or waiting for some resources.

It also contains the information about all the instances of all the resources whether they are available or
being used by the processes.

In Resource allocation graph, the process is represented by a Circle while the Resource is represented by
a rectangle. Let's see the types of vertices and edges in detail.

VERTICES
Deadlock Detection and Recovery

In this approach, The OS doesn't apply any mechanism to avoid or prevent the deadlocks. Therefore the
system considers that the deadlock will definitely occur. In order to get rid of deadlocks, The OS
periodically checks the system for any deadlock. In case, it finds any of the deadlock then the OS will
recover the system using some recovery techniques.

The main task of the OS is detecting the deadlocks. The OS can detect the deadlocks with the help of
Resource allocation graph.
In order to recover the system from deadlocks, either OS considers resources or processes.

For Resource

Preempt the resource

We can snatch one of the resources from the owner of the resource (process) and give it to the other
process with the expectation that it will complete the execution and will release this resource sooner.
Well, choosing a resource which will be snatched is going to be a bit difficult.

Rollback to a safe state

System passes through various states to get into the deadlock state. The operating system canrollback
the system to the previous safe state. For this purpose, OS needs to implement check pointing at every
state.

The moment, we get into deadlock, we will rollback all the allocations to get into the previous safe state.

For Process

Kill a process

Killing a process can solve our problem but the bigger concern is to decide which process to kill.
Generally, Operating system kills a process which has done least amount of work until now.

Kill all process

This is not a suggestible approach but can be implemented if the problem becomes very serious. Killing
all process will lead to inefficiency in the system because all the processes will execute again from
starting.
DISK SCHEDULING

As we know, a process needs two type of time, CPU time and IO time. For I/O, it requests the Operating
system to access the disk.

However, the operating system must be fare enough to satisfy each request and at the same time,
operating system must maintain the efficiency and speed of process execution.

The technique that operating system uses to determine the request which is to be satisfied next is called
disk scheduling.

Seek Time

Seek time is the time taken in locating the disk arm to a specified track where the read/write request
will be satisfied.

Rotational Latency

It is the time taken by the desired sector to rotate itself to the position from where it can access the
R/W heads.

Transfer Time

It is the time taken to transfer the data.

Disk Access Time

Disk access time is given as,

Disk Access Time = Rotational Latency + Seek Time + Transfer Time

Disk Response Time

It is the average of time spent by each request waiting for the IO operation.

Purpose of Disk Scheduling

The main purpose of disk scheduling algorithm is to select a disk request from the queue of IO requests
and decide the schedule when this request will be processed.

GOAL OF DISK SCHEDULING

-> Fairness

-> High Throughput

-> Minimal Travelling Head Time

Disk Scheduling Algorithms


The list of various disks scheduling algorithm is given below. Each algorithm is carrying some advantages
and disadvantages. The limitation of each algorithm leads to the evolution of a new algorithm.

FCFS scheduling algorithm

SSTF (shortest seek time first) algorithm

SCAN scheduling

C-SCAN scheduling

LOOK Scheduling

C-LOOK scheduling

Fixed Partitioning

The earliest and one of the simplest technique which can be used to load more than one processes into
the main memory is Fixed partitioning or Contiguous memory allocation.

In this technique, the main memory is divided into partitions of equal or different sizes. The operating
system always resides in the first partition while the other partitions can be used to store user
processes. The memory is assigned to the processes in contiguous way.

In fixed partitioning,

The partitions cannot overlap.

A process must be contiguously present in a partition for the execution.

1. Internal Fragmentation

If the size of the process is lesser then the total size of the partition then some size of the partition get
wasted and remain unused. This is wastage of the memory is alled internal fragmentation.

As shown in the image below, the 4 MB partition is used to load only 3 MB process and the remaining 1
MB got wasted

2. External Fragmentation

The total unused space of various partitions cannot be used to load the processes even though there is
space available but not in the contiguous form.
As shown in the image below, the remaining 1 MB space of each partition cannot be used as a unit to
store a 4 MB process. Despite of the fact that the sufficient space is available to load the process,
process will not be loaded.

Dynamic Partitioning :

Dynamic partitioning tries to overcome the problems caused by fixed partitioning. In this technique, the
partition size is not declared initially. It is declared at the time of process loading.

The first partition is reserved for the operating system. The remaining space is divided into parts. The
size of each partition will be equal to the size of the process. The partition size varies according to the
need of the process so that the internal fragmentation can be avoided.
Advantages :

No internal fragmentation.

No limittiion on the size of the process.

Disadvantages :

External Fragmentation

Complex Memory Allocation

COMPACTION

We can also use compaction to minimize the probability of external fragmentation. In compaction, all
the free partitions are made contiguous and all the loaded partitions are brought together.

By applying this technique, we can store the bigger processes in the memory. The free partitions are
merged which can now be allocated according to the needs of new processes. This technique is also
called defragmentation.

Linked List for Dynamic Partitioning

The better and the most popular approach to keep track the free or filled partitions is using Linked List.
In this approach, the Operating system maintains a linked list where each node represents each
partition. Every node has three fields.

First field of the node stores a flag bit which shows whether the partition is a hole or some process is
inside.

Second field stores the starting index of the partition.

Third filed stores the end index of the partition.

If a partition is freed at some point of time then that partition will be merged with its adjacent free
partition without doing any extra effort.

There are some points which need to be focused while using this approach
PAGING

Need for Paging

Lets consider a process P1 of size 2 MB and the main memory which is divided into three partitions. Out
of the three partitions, two partitions are holes of size 1 MB each.

P1 needs 2 MB space in the main memory to be loaded. We have two holes of 1 MB each but they are
not contiguous.

Although, there is 2 MB space available in the main memory in the form of those holes but that remains
useless until it become contiguous. This is a serious problem to address.

We need to have some kind of mechanism which can store one process at different locations of the
memory.

The Idea behind paging is to divide the process in pages so that, we can store them in the memory at
different holes.

Paging in OS (Operating System)

In Operating Systems, Paging is a storage mechanism used to retrieve processes from the secondary
storage into the main memory in the form of pages.
The main idea behind the paging is to divide each process in the form of pages. The main memory will
also be divided in the form of frames.

One page of the process is to be stored in one of the frames of the memory. The pages can be stored at
the different locations of the memory but the priority is always to find the contiguous frames or holes.

Pages of the process are brought into the main memory only when they are required otherwise they
reside in the secondary storage.

Example

Let us consider the main memory size 16 Kb and Frame size is 1 KB therefore the main memory will be
divided into the collection of 16 frames of 1 KB each.

There are 4 processes in the system that is P1, P2, P3 and P4 of 4 KB each. Each process is divided into
pages of 1 KB each so that one page can be stored in one frame.

Initially, all the frames are empty therefore pages of the processes will get stored in the contiguous way.

Frames, pages and the mapping between the two is shown in the image below.
What is Virtual Memory in OS (Operating System)?

Virtual Memory is a storage scheme that provides user an illusion of having a very big main memory.
This is done by treating a part of secondary memory as the main memory.

In this scheme, User can load the bigger size processes than the available main memory by having the
illusion that the memory is available to load the process.

Instead of loading one big process in the main memory, the Operating System loads the different parts
of more than one process in the main memory.

By doing this, the degree of multiprogramming will be increased and therefore, the CPU utilization will
also be increased.

Working
whenever some pages needs to be loaded in the main memory for the execution and the memory is not
available for those many pages, then in that case, instead of stopping the pages from entering in the
main memory, the OS search for the RAM area that are least used in the recent times or that are not
referenced and copy that into the secondary memory to make the space for the new pages in the main
memory.

Demand Paging

Demand Paging is a popular method of virtual memory management. In demand paging, the pages of a
process which are least used, get stored in the secondary memory.

A page is copied to the main memory when its demand is made or page fault occurs. There are various
page replacement algorithms which are used to determine the pages which will be replaced. We will
discuss each one of them later in detail.

EXAMLE OF VIRTUAL MEMORY

Let us assume 2 processes, P1 and P2, contains 4 pages each. Each page size is 1 KB. The main
memory000ntains 8 frame of 1 KB each. The OS resides in the first two partitions. In the third partition,
1st page of P1 is stored and the other frames are also shown as filled with the different pages of
processes in the main memory.

The page tables of both the pages are 1 KB size each and therefore they can be fit in one frame each.
The page tables of both the processes contain various information that is also shown in the image.

The CPU contains a register which contains the base address of page table that is 5 in the case of P1 and
7 in the case of P2. This page table base address will be added to the page number of the Logical address
when it comes to accessing the actual corresponding entry.
Advantages of Virtual Memory

The degree of Multiprogramming will be increased.

User can run large application with less real RAM.

Disadvantage of Virtual Memory

The system becomes slower since swapping takes time.

It takes more time in switching between applications.

--------------------------------------------------------------------------------------------------------

Cache Memory

The data or contents of the main memory that are used frequently by CPU are stored in the cache
memory so that the processor can easily access that data in a shorter time. Whenever the CPU needs to
access memory, it first checks the cache memory. If the data is not found in cache memory, then the
CPU moves into the main memory.

Cache memory is placed between the CPU and the main memory. The block diagram for a cache
memory can be represented as:
The cache is the fastest component in the memory hierarchy and approaches the speed of CPU
components.

Cache memory is organised as distinct set of blocks where each set contains a small fixed number of
blocks

Cache Mapping:

There are three different types of mapping used for the purpose of cache memory which are as
follows:

Direct mapping,

Associative mapping

Set-Associative mapping

NOTE : The mapping is typically done using the modulo operation:

Cache line = Memory address mod Number of cache lines

Cache line=Memory addressmodNumber of cache lines.

Direct Mapping

The simplest technique, known as direct mapping, maps each block of main memory into only one
possible cache line. or In Direct mapping, assign each memory block to a specific line in the cache. If a
line is previously taken up by a memory block when a new block needs to be loaded, the old block is
trashed
2. Associative Mapping

In this type of mapping, associative memory is used to store the content and addresses of the memory
word. Any block can go into any line of the cache. This means that the word id bits are used to identify
which word in the block is needed, but the tag becomes all of the remaining bits.
3. Set Associative Mapping

This form of mapping is an enhanced form of direct mapping where the drawbacks of direct mapping
are removed. Set associative addresses the problem of possible thrashing in the direct mapping method.
It does this by saying that instead of having exactly one line that a block can map to in the cache, we will
group a few lines together creating a set. Then a block in memory can map to any one of the lines of a
specific set.
Memory Management Unit

The purpose of Memory Management Unit (MMU) is to convert the logical address into the physical
address. The logical address is the address generated by the CPU for every page while the physical
address is the actual address of the frame where each page will be stored.

When a page is to be accessed by the CPU by using the logical address, the operating system needs to
obtain the physical address to access that page physically.

The logical address has two parts.

Page Number The page number identifies which page of the logical address space the address belongs
to.

Offset It determines the displacement from the beginning of the page to the actual address.

Physical Address Space

Physical address space in a system can be defined as the size of the main memory. It is really important
to compare the process size with the physical address space. The process size must be less than the
physical address space.
Logical Address Space

Logical address space can be defined as the size of the process. The size of the process should be less
enough so that it can reside in the main memory.

Page Table in OS

Page Table is a data structure used by the virtual memory system to store the mapping between logical
addresses and physical addresses.

Logical addresses are generated by the CPU for the pages of the processes therefore they are generally
used by the processes.

Physical addresses are the actual frame address of the memory. They are generally used by the
hardware or more specifically by RAM subsystems.

LETS TAKE AN EXAMPLE

Physical Address Space = M words

Logical Address Space = L words

Page Size = P words

Physical Address = log 2 M = m bits

Logical Address = log 2 L = l bits

page offset = log 2 P = p bits


BEST FIT : - The bet fit algorithm tries find out the smallest possibe hole in that list which can
accomodate the size requirements of the process.

disadvantage

It is generally slow as it scans the lit each time to find out the smallest hole possible.

Due to the fact that the difference between the hole size and the process size is very small , it cant load
any other process and therefore remains useless.

WORST FIT : - The Worst Fit algorithm tries to scan the entire list evry time and find out the biggest
possible hole that can fullfill the requirement of the process.
disadvantages :

It is generally slow as it scans the lit each time to find out the smallest hole possible.

FIRST FIT : - The first fit algorithms scans the entire list and whenever it finds the first fit hole big enough
to load the entire process It stops scanning and loads the process into that hole.

It produces bigger hole as compared to other algorithms.

To place the processes in the memory partitions using first-fit, best-fit, and worst-fit strategies, we will
follow the specific rules of each strategy:

First-Fit: Allocate the first partition that is big enough.

Best-Fit: Allocate the smallest partition that is big enough.

Worst-Fit: Allocate the largest partition that is big enough.

Let's examine each strategy in detail with the given memory partitions and processes:

Memory Partitions (in KB): 100, 500, 200, 300, 600

Process Sizes (in KB): 212, 417, 112, 426

1. First-Fit Strategy

Steps:

Process 212 KB: Fits in 500 KB partition (first that fits).


Process 417 KB: Fits in 600 KB partition (first that fits).

Process 112 KB: Fits in 200 KB partition (first that fits).

Process 426 KB: Fits in 300 KB partition (first that fits).

Result:

Memory Partitions: 100, 288 (500 - 212), 88 (200 - 112), -126 (300 - 426), 183 (600 - 417)

Final Allocation:

212 KB -> 500 KB

417 KB -> 600 KB

112 KB -> 200 KB

426 KB -> Not allocated (no suitable partition)

2. Best-Fit Strategy

Steps:

Process 212 KB: Fits in 300 KB partition (smallest that fits).

Process 417 KB: Fits in 500 KB partition (smallest that fits).

Process 112 KB: Fits in 200 KB partition (smallest that fits).

Process 426 KB: Fits in 600 KB partition (smallest that fits).

Result:

Memory Partitions: 100, 83 (300 - 212), 283 (500 - 417), 88 (200 - 112), 174 (600 - 426)

Final Allocation:

212 KB -> 300 KB

417 KB -> 500 KB

112 KB -> 200 KB


426 KB -> 600 KB

3. Worst-Fit Strategy

Steps:

Process 212 KB: Fits in 600 KB partition (largest that fits).

Process 417 KB: Fits in 500 KB partition (largest that fits).

Process 112 KB: Fits in 300 KB partition (largest that fits).

Process 426 KB: Not allocated (no suitable partition left).

Result:

Memory Partitions: 100, 83 (500 - 417), 200, 188 (300 - 112), 388 (600 - 212)

Final Allocation:

212 KB -> 600 KB

417 KB -> 500 KB

112 KB -> 300 KB

426 KB -> Not allocated (no suitable partition)

Efficiency Deduction

First-Fit:

Pros: Simple and fast.

Cons: Leaves larger gaps and results in external fragmentation.

Best-Fit:

Pros: Minimizes leftover space and more efficient in terms of space utilization.

Cons: Slower, as it must search the entire list of partitions.


Worst-Fit:

Pros: Reduces the chance of fragmentation by leaving larger partitions.

Cons: Can leave large unused partitions and potentially waste more space.

Conclusion:

For the given scenario, Best-Fit is the most efficient strategy as it manages to allocate all the processes
without leaving large gaps, thereby maximizing the utilization of memory. It successfully allocates all
processes within available partitions, leaving smaller fragments than the other two strategies.

FILE ALLOCATION METHODS :

File allocation methods define how the files are to be stored in the disk blocks.

There are three main disk space or file space allocation methods.

i. Contiguous ii. Linked iii. Indexed

The main idea behind these methods is to provide :

Efficient Disk Space Utilization.

Fast access to the file blocks.

Contiguous : In this scheme , each file occupies the contiguous set of blocks on the disk . for example if a
file requires n blocks and is given block 'b' as the starting location then the blocks assigned to the file will
be : b , b+1 , b+2 , b+3 ...........b+n-1.

the directory entry for the cintiguous file blocks will contain :

The address of the starting block.

The length of the allocated portion.

FOR EXAMPLE : - The file ‘mail’ starts from the block 19 with length = 6 blocks. Therefore, it occupies 19,
20, 21, 22, 23, 24 blocks.
Adavntages :

-> Both Sequential and Direct Access are supported by this. For example direct access of the kth block
can be obtained by staritng from block b and adding k to it i.e kth block address = (b+k).

-> This is extremely fast as the number of seeks are minimal bacause of the contiguous allocation of file
blocks.

Disadavantages :

It suffers from both inernal as well as external fragmentation. This makes it inefficient in terms of
memory utilization.

Increasing file size is difficult as it depends on the availability of the contiguous memory at a particular
instance.

Linked List Allocation : - In this scheme each file is a linked list of disk blocks that need not be
contiguous . It can be scattered all over the disk.

The directory entry contains a pointer to the startiing block and the ending file block. Eeah block poinyer
points to the next block.
Advantages : -

It is bery flexible in terms of file size. As the size of thee file can be increased easily since the sytem
doesn't require contiguous chunks of memory.

It does not suffer from esternal fragmentation. This makes it relatively better in terms of memory
utilization.

Disadvantages : -

Since the file blocks are dsitributed randomly on the disk. A Large number of seeks are required to
access every block individually. This makes linked allocation slower.

It doesn't support random or direct memory access.A block k of a file can be accessed by traversing k
blocks sequentially (sequential access ) from the starting block of the file via block pointers.

Pointers are required which includes some extra overhead.

Indexed Allocation : - In this scheme, a special block known as the index block contains the pointers to
all the blocks occupied by a file. Eeach file has its own index block. The ith entry of the index block will
contain the address of the ith file block.

The directory entry contains the address of the index block.


Advantages :

It supports direct accesss to the memory block.Therefore providing fast access to the file blocks.

It overcomes the problem of external fragmentation.

Disadvantages :

Pointer overhead for indexed allocation is greater than the linked list allocation.

For the files that are very large single index block may not be able to hold all the pointers.

Following mechanism can be used to resolve this :

1. Linked Scheme : This scheme link two or more index blocks together for holding the pointers. Every
index block would then contain a pointer or the address of the next block.

2. Multilevel Indexing : in this policy first level index is used to point to the second level index block
which in turn points to the disk blocks occupied by the file.. This can be extended to 3 or more levels
depending upon the file size.

System Calls : - The interface between a process and an operating system is provided by the system
calls. in general these system calls are availiable as assembly level instructions. They are also included
in the manuals used by assembly level programmers . a system calls are made when a process in the
user mode requires access to a resource. Then these system calls requests the kernel to provide the
resource via system calls.

It can arise in following situations :

1. If a user wants to read or write a file .

2. Creation and Management of new process.


3. Network connections like sending and receiving packets.

4. Access to a hardware device such as printer , scanner etc.

There are mainly five types of system calls : -

1. Process Control : - These system calls deals with the processess such as process creation , process
termination etc.

2. File Management : - These system calls deals with file manipulation such as , creating , reading ,
writng and deleting a file. etc...

3. Device Management : - These system calls are responsible for device manipulation , such as reading
from device buffers and writing into device buffers etc..

4. Information Management : - These system calls deals with the information and its transfer between
the operating system and the user program.

5. Communication : - These system calls are responsilbe for interprocess communication , They are also
responsible for creating and deleting a communication connection.

Purpose of System Calls : -

open() :

The open() system call is used to provide access to a file in a file system. This system call allocates
resources to the file and provides a handle that the process uses to refer to the file.

read() :

The read() system call is used to access data from a file that is stored in the file system. The file to read
can be identified by its file descriptor and it should be opened using open() before it can be read.

write() :

The write() system call writes the data from a user buffer into a device such as a file. This system call is
one of the ways to output data from a program.

close() :

The close() system call is used to terminate access to a file system. Using this system call means that the
file is no longer required by the program and so the buffers are flushed, the file metadata is updated
and the file resources are de-allocated.

wait() :

In some systems, a process may wait for another process to complete its execution. This happens
when a parent process creates a child process and the execution of the parent process is suspended
until the child process executes. The suspending of the parent process occurs with a wait() system call.

fork() :
Processes use the fork() system call to create processes that are a copy of themselves. This is one of the
major methods of process creation in operating systems.

kill() :

The kill() system call is used by the operating system to send a termination signal to a process that urges
the process to exit.

Buffering : Buffeering is the process of stroring the data in a temporary storage area , called a buffer ,
while it is being transferred from one place to another.

purpose : - Buffer are used to handle differences in the speed at which the data is processed. For
instance , a buffer can hold data that is sent from a fast device(like a CPU) to a slower device(printers) to
prevent the fast device from waiting.

Spooling : (Simultaneous Peripheral Operations On-Line) is a process in which the data is temporarily
held to be used and exectuted by a device , program or system. It involves queuing the data to be
processed in a specific order.

Purpose : Spooling manages the data by queuing it so that slower devices can work independently and
efficiently without direct interaction from the faster devices.

Time Sharing : Time Sharing is the method that allows multiple users to share the computing resources
of a single system simultaneously. It enables many users to interact with the computer at the same time.

Purpose : To maximize the efficiency and responsiveness of computing resources by allocating time slots
to multiple users or tasks.

Mechanism : Scheduling ----> Time Slicing ----> Context Switching.

Distributed System : A distributed system is a network of independent computers that work together as
a single system to achieve a common goal.

Purpose : To provide scalability , resource sharing , and fault tolerance by distributing tasks across
multiple machines.

------------------------------------------------------------------------------------------------------------------------

Dispatcher : Dipatcher is a component of the operating system responsible for assigning the CPU to
processes in the ready queue.

Purpose : To switch the CPU focus from one process to another , ensuring efficient use of the CPU.

Functions : Context Switching ---> Process Scheduling ---> Execution Control.

Dispatch Latency : Dispatch Latrency is the time taken by the dispatcher to stop one process and start or
resume another.
Factors influencing Dispatch Latency :

-> Hardware Efficiency

-> Scheduling Algorithms

-> System Load

-> Context Switching

NOTE : lower the dispatch latency more responsive is the system.

Optimization of Scheduling Criteria :

Definition : Optimization of scheduling criteria invloves improving the perfomance of the process
scheduling mechanism by optimising various criteria.

Common Criteria :

* CPU Utilization - Maximizing the use of the CPU.

* Throughput - Maximum number of process completed in a given time.

* Turnaround Time - Minimizing the total time taken by the process from submission to
completion.

* Waiting Time - Minimizing the time the process spends in the ready queue.

* Response Time - Miniminzg the time of the submission of a request to the first response.

various techniques include : - Priority Scheduling , Round Robin Scheduling , Shortest Job Next , Multi
level Queue Scheduling. etc....

Swapping : Swapping is a memory management technique in which processes are temporarily


transferred from the main memory to a secondary storage (like a hard disk) and brought back to the
main memory as needed.

Purpose : To free up the main memory for other processes when the system is running low on memory.

Context Switching :Context switching is the process of saving the state of a currently running process
and loading the state of another process to start or resume its execution.

Purpose: To enable multitasking by allowing the CPU to switch between multiple processes.

NOTE : Overhead: Context switching incurs overhead due to the time spent saving and loading process
states. Minimizing this overhead is crucial for efficient system performance.

------------------------------------------------------------------------------------------------------------------------
I/O SUBSYSTEM

The Kernel I/O Subsystem provides an interface between the operating system and input/output (I/O)
devices. I/O Subsystem manages the I/O requests made by the user applications and translates them
into hardware commands that the devices can understand.

Several services such as Scheduling , Spooling , Caching , Device Registration ,Error Handling and
Protection , are provided by the I/O subsystem which are built uon the hardware and device drivers
infrastructure.

I/O scheduling - Scheduling can imrove the overall efficiency of the system and can have a fair acess of
the requested devices by ensuring minimum turn around time(TAT) , Waiting Time (WT) and Response
Time for I/O to complete.

OS Developers maitains a waiting queue for each for the requested I/O devices.When a blocking system
call is generated for any IO device. The request is placed in the queue for that articular device.The order
of the is chaged by the io scheduler every time every time to ensure systems performance.

I/O Buffering - Buffering is the memory area that stores data being tranferred between the devices or
between the devices and the application. I/O buffering is mainly done for 3 reasons

1. First is to cope with the speed mismatch between the roducer and consumer data stream.

2. To rovide data adaptation that have different data tranfer sizes

3. To support the "copy semantics" for the application I/O.

copy semantics Suppose an alication wants to weite the data that has been stored in the I/O buffer then
it would call the write() system call and the pointer will point to the bufffer along with the intetger
secifying the number of bytes to write.

Caching - A cache is a region of fast memory that holds a copy of data. Access to the cached copy is
much easier than the original file.The main difference between a buffer and a cache is that a buffer may
hold only the existing copy of a data item, while a cache, by definition, holds a copy on faster storage of
an item that resides elsewhere.

Spooling and Device Reservation – A spool is a buffer that holds the output of a device, such as a
printer that cannot accept interleaved data streams. Although a printer can serve only one job at a
time, several applications may wish to print their output concurrently, without having their output mixes
together. Because the output of all alciations are sooled on a seerate disk files. When an application
finishes spooling then the system queues the corresponding spool file as an outpuut to the printer.

Error Handling - The strategies employed for error handling involve mechanisms for detecting,
reporting, and recovering from I/O errors. Below are key components of error handling strategies within
the Kernel I/O Subsystem

1. Error Detection Mechanisms:The Kernel I/O Subsystem incorporates various mechanisms to detect
I/O errors promptly

2. Error Reporting:Once an error is detected, the Kernel I/O Subsystem employs mechanisms to report
the error to higher levels of the operating system or user applications
3. Error Recovery Mechanisms:Recovering from I/O errors is crucial to maintaining system stability.

4.User Notification:Informing users or administrators about I/O errors is essential for timely
intervention and system maintenance:

User Alerts: Providing alerts to users, either through the user interface or system notifications, can
prompt immediate attention to potential issues.

Automated Notifications: Implementing automated notification systems, such as emails or messages, to


inform system administrators about critical errors for proactive system management.

I/O Protection –

Errors and the issue of protection are closely related. A user process may attempt to issue illegal I/O
instructions to disrupt the normal function of a system. We can use the various mechanisms to ensure
that such disruption cannot take place in the system.

RAID - RAID or redundant array of independent disks is a data storage virtualization technology that
combines multiple physical disk drive components into one or more logical units for data redundancy,
performance improvement, or both.

It is a way of storing the same data in different places on multiple hard disks or solid-state drives to
protect data in the case of a drive failure. A RAID system consists of two or more drives working in
parallel. These can be hard discs, but there is a trend to use SSD technology (Solid State Drives).

RAID combines several independent and relatively small disks into single storage of a large size. The
disks included in the array are called array members. The disks can combine into the array in different
ways, which are known as RAID levels. Each of RAID levels has its own characteristics of:

Fault-tolerance is the ability to survive one or several disk failures.

Performance shows the change in the read and writes speed of the entire array compared to a single
disk.

The array's capacity is determined by the amount of user data written to the array. The array capacity
depends on the RAID level and does not always match the sum of the RAID member disks' sizes

RAID 0: Stripes data across multiple disks for improved performance, but with no redundancy.

RAID 1: Mirrors data on two or more disks for redundancy, improving data security.

RAID 5: Stripes data and parity information across three or more disks, providing a balance of improved
performance and redundancy.

RAID 6: Similar to RAID 5 but with double parity, allowing for the failure of two disks.

RAID 10: Combines RAID 1 and RAID 0, providing both redundancy and performance improvements.

-----------------------------------------------------------------------------------------------------------------------------

What is a File ?
The File can be defined as a data strucuture which stores the sequence of records. The file is stored
inside the File System that may exsist on the disk or inside the main - memory.

The file can be simple or complex.

The collection of File is known as the Directory and the collection of directories at different levels can be
called as a File System.

Attributes of the File

1.Name

Every file carries a name by which the file is recognized in the file system. One directory cannot have
two files with the same name.

2.Identifier

Along with the name, Each File has its own extension which identifies the type of the file. For example,
a text file has the extension .txt, A video file can have the extension .mp4.

3. Type

In a File System, the Files are classified in different types such as video files, audio files, text files,
executable files, etc.
4.Location

In the File System, there are several locations on which, the files can be stored. Each file carries its
location as its attribute.

5.Size

The Size of the File is one of its most important attribute. By size of the file, we mean the number of
bytes acquired by the file in the memory.

6.Protection

The Admin of the computer may want the different protections for the different files. Therefore each
file carries its own set of permissions to the different group of Users.

7.Time and Date

Every file carries a time stamp which contains the time and date on which the file is last modified.

What is a directory?

Directory can be defined as the listing of the related files on the disk. The directory may store some or
the entire file attributes.

To get the benefit of different file systems on the different operating systems, A hard disk can be divided
into the number of partitions of different sizes. The partitions are also called volumes or mini disks.

Each partition must have at least one directory in which, all the files of the partition can be listed. A
directory entry is maintained for each file in the directory which stores all the information related to
that file.

A directory can be viewed as a file which contains the meta data of the bunch of files.
TYPES OF DIRECTORIES

Single Level Directory

The simplest method is to have one big list of all the files on the disk. The entire system will contain only
one directory which is supposed to mention all the files present in the file system. The directory
contains one entry per each file present on the file system.

Two Level Directory

In two level directory systems, we can create a separate directory for each user. There is one iaster
directory which contains separate directories dedicated to each user. For each user, there is a different
directory present at the second level, containing group of user's file. The system doesn't let a user to
enter in the other user's directory without permission.

NOTE: i. Same kind of file cannot be grouped into a single directory.

ii. Searching becomes efficient as only one user's list need to be traversed.

iii. Different user cn have the same file name.

Tree Structured Directory


In Tree structured directory system, any directory entry can either be a file or sub directory. Tree
structured directory system overcomes the drawbacks of two level directory system. The similar kind of
files can now be grouped in one directory.

Each user has its own directory and it cannot enter in the other user's directory. However, the user has
the permission to read the root's data but he cannot write or modify this.

FILE SYSTEM

File system is the part of the operating system which is responsible for file management. It provides a
mechanism to store the data and access to the file contents including data and programs. Some
Operating systems treats everything as a file for example Ubuntu.

The File system takes care of the following issues

File Structure

We have seen various data structures in which the file can be stored. The task of the file system is to
maintain an optimal file structure.

Recovering Free space

Whenever a file gets deleted from the hard disk, there is a free space created in the disk. There can be
many such spaces which need to be recovered in order to reallocate them to other files.

disk space assignment to the files

The major concern about the file is deciding where to store the files on the hard disk. There are various
disks scheduling algorithm via which OS determines the optimal positioning of the file on a disk.

tracking data location

A File may or may not be stored within only one block. It can be stored in the non contiguous blocks on
the disk. We need to keep track of all the blocks on which the part of the files reside.
-------------------------------------------------------------------------------------

File System Structure

File System provide efficient access to the disk by allowing data to be stored, located and retrieved in a
convenient way. A file System must be able to store the file, locate the file and retrieve the file.

Most of the Operating Systems use layering approach for every task including file systems. Every layer
of the file system is responsible for some activities.
When an application program asks for a file, the first request is directed to the logical file system. The
logical file system contains the Meta data of the file and directory structure. If the application program
doesn't have the required permissions of the file then this layer will throw an error.

Generally, files are divided into various logical blocks. Files are to be stored in the hard disk and to be
retrieved from the hard disk. Hard disk is divided into various tracks and sectors. Therefore, in order to
store and retrieve the files, the logical blocks need to be mapped to physical blocks. This mapping is
done by File organization module. It is also responsible for free space management.

Once File organization module decided which physical block the application program needs, it passes
this information to basic file system. The basic file system is responsible for issuing the commands to
I/O control in order to fetch those blocks.

I/O controls contain the codes by using which it can access hard disk. These codes are known as device
drivers. I/O controls are also responsible for handling interrupts.

You might also like