Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views51 pages

UNIT-1: An Operating System (OS)

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)
3 views51 pages

UNIT-1: An Operating System (OS)

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/ 51

UNIT-1

An Operating System (OS) is an interface between a computer user and computer


hardware. An operating system is a software which performs all the basic tasks
like file management, memory management, process management, handling
input and output, and controlling peripheral devices such as disk drives and
printers.
System Software: are the software which are more complex in nature and
they are more near to computer hardware. This software is usually written
in low-level languages like assembly language and includes Operating
Memory Management: a collection of data in a specific format. It is used to store
instructions and processed data. The memory comprises a large array or group of
words or bytes, each with its own location.
Main memory is central to the operation of a modern computer. Main Memory is
a large array of words or bytes, ranging in size from hundreds of thousands to
billions. It is repository of rapidly available information shared by the CPU and I/O
devices.
Why Memory Management is required:
• Allocate and de-allocate memory before and after process execution.
• To keep track of used memory space by processes.
• To minimize fragmentation issues.
• To proper utilization of main memory.
• To maintain data integrity while executing of process.
Logical Address space: An address generated by the CPU is known as a “Logical
Address”. It is also known as a Virtual address. Logical address space can be
defined as the size of the process. A logical address can be changed.
Physical Address space: An address seen by the memory unit (i.e the one loaded
into the memory address register of the memory) is commonly known as a
“Physical Address”. The set of all physical addresses corresponding to these
logical addresses is known as Physical address space. A physical address is
computed by MMU. The run-time mapping from virtual to physical addresses is
done by a hardware device Memory Management Unit (MMU). The physical
address always remains constant.

1
Static and Dynamic Loading:
There are two different types of loading:
Static loading: - loading the entire program into a fixed address. It requires more
memory space.
Dynamic loading: - The entire program and all data of a process must be in physical
memory for the process to execute. So, the size of a process is limited to the size of
physical memory. To gain proper memory utilization, dynamic loading is used.

Static and Dynamic linking:


A linker is a program that takes one or more object files generated by a compiler
and combines them into a single executable file.
Static linking: In static linking, the linker combines all necessary program modules
into a single executable program. So, there is no runtime dependency. Some
operating systems support only static linking, in which system language libraries
are treated like any other object module.
Dynamic linking: The basic concept of dynamic linking is similar to dynamic
loading. In dynamic linking, “Stub” is included for each appropriate library routine
reference. A stub is a small piece of code. When the stub is executed, it checks
whether the needed routine is already in memory or not. If not available then the
program loads the routine into memory.
Free space management
The system keeps tracks of the free disk blocks for allocating space to files when
they are created. Also, to reuse the space released from deleting the files, free
space management becomes crucial. The system maintains a free space list which
keeps track of the disk blocks that are not allocated to some file or directory. The
free space list can be implemented mainly as:
Bitmap or Bit vector : A Bitmap or Bit Vector is series or collection of bits where
each bit corresponds to a disk block. The bit can take two values: 0 and 1: 0
indicates that the block is allocated and 1 indicates a free block.
Advantages 1- Simple to understand, 2- Finding the first free block is efficient.

Linked List: In this approach, the free disk blocks are linked together i.e. a free
block contains a pointer to the next free block. The block number of the very first
disk block is stored at a separate location on disk and is also cached in memory.

2
Grouping: This approach stores the address of the free blocks in the first free
block. The first free block stores the address of some, say n free blocks. Out of
these n blocks, the first n-1 blocks are actually free and the last block contains the
address of next free n blocks.
An advantage of this approach is that the addresses of a group of free disk blocks
can be found easily.
Counting: This approach stores the address of the first free disk block and a
number n of free contiguous disk blocks that follow the first block.
Every entry in the list would contain:
1- Address of first free disk block
2-A number n

External fragmentation
External fragmentation occurs whenever a method of dynamic memory
allocation happens to allocate some memory and leave a small amount of
unusable memory. The total quantity of the memory available is reduced
substantially in case there’s too much external fragmentation.
Internal Fragmentation:
Internal fragmentation happens when the memory is split into mounted-sized
blocks. Whenever a method is requested for the memory, the mounted-sized
block is allotted to the method. In the case where the memory allotted to the
method is somewhat larger than the memory requested, then the difference
between allotted and requested memory is called internal fragmentation. We
fixed the sizes of the memory blocks, which has caused this issue. If we use
dynamic partitioning to allot space to the process, this issue can be solved.
2. External Fragmentation:
External fragmentation happens when there’s a sufficient quantity of area within
the memory to satisfy the memory request of a method. However, the process’s
memory request cannot be fulfilled because the memory offered is in a non-
contiguous manner. Whether you apply a first-fit or best-fit memory allocation
strategy it’ll cause external fragmentation.

3
Segmented memory A process is divided into Segments. The chunks that a
program is divided into which are not necessarily all of the same sizes are called
segments. Segmentation gives the user’s view of the process which paging does
not give. Here the user’s view is mapped to physical memory. There are types of
segmentation:
• Virtual memory segmentation – Each process is divided into a number of
segments, not all of which are resident at any one point in time.
• Simple segmentation – Each process is divided into a number of segments,
all of which are loaded into memory at run time, though not necessarily
contiguously.
There is no simple relationship between logical addresses and physical addresses
in segmentation. A table stores the information about all such segments and is
called Segment Table. Segment Table – It maps two-dimensional Logical address
into one-dimensional Physical address. It’s each table entry has:
Base Address: It contains the starting physical address where the segments reside
in memory.
Limit: It specifies the length of the segment.
Translation of Two-dimensional Logical Address to dimensional Physical
Address.

4
Address generated by the CPU is divided into:
Segment number (s): Number of bits required to represent the segment.
Segment offset (d): Number of bits required to represent the size of the segment.
Advantages of Segmentation –
No Internal fragmentation.
Segment Table consumes less space in comparison to Page table in paging.
As a complete module is loaded all at once, segmentation improves CPU
utilization.
The user’s perception of physical memory is quite similar to segmentation. Users
can divide user programmed into modules via segmentation. These modules are
nothing more than the separate processes’ codes.
The user specifies the segment size, whereas in paging, the hardware determines
the page size.
Segmentation is a method that can be used to segregate data from security
operations.
Disadvantage of Segmentation –
As processes are loaded and removed from the memory, the free memory space
is broken into little pieces, causing External fragmentation.
Overhead is associated with keeping a segment table for each activity.
Due to the need for two memory accesses, one for the segment table and the
other for main memory, access time to retrieve the instruction increase

Paging is a memory management scheme that eliminates the need for contiguous
allocation of physical memory. The process of retrieving processes in the form of
pages from the secondary storage into the main memory is known as paging. The
basic purpose of paging is to separate each procedure into pages. Additionally,
frames will be used to split the main memory. This scheme permits the physical
address space of a process to be non – contiguous.

5
Let us look some important terminologies:
• Logical Address or Virtual Address (represented in bits): An address
generated by the CPU
• Logical Address Space or Virtual Address Space( represented in words or
bytes): The set of all logical addresses generated by a program
• Physical Address (represented in bits): An address actually available on
memory unit
• Physical Address Space (represented in words or bytes): The set of all
physical addresses corresponding to the logical addresses
Features of paging:
• Mapping logical address to physical address.
• Page size is equal to frame size.
• Number of entries in a page table is equal to number of pages in logical
address space.
• The page table entry contains the frame number.
• All the page table of the processes are placed in main memory.

The mapping from virtual to physical address is done by the memory


management unit (MMU) which is a hardware device and this mapping is known
as paging technique.
The Physical Address Space is conceptually divided into a number of fixed-size
blocks, called frames.
The Logical address Space is also splitted into fixed-size blocks, called pages. Page
Size = Frame Size
Page number(p): Number of bits required to represent the pages in Logical
Address Space or Page number
Page offset(d): Number of bits required to represent particular word in a page or
page size of Logical Address Space or word number of a page or page offset.
Physical Address is divided into
Frame number(f): Number of bits required to represent the frame of Physical
Address Space or Frame number.
Frame offset(d): Number of bits required to represent particular word in a frame
or frame size of Physical Address Space or word number of a frame or frame
offset.

6
The hardware implementation of page table can be done by using dedicated
registers. But the usage of register for the page table is satisfactory only if page
table is small. If page table contain large number of entries then we can use
TLB(translation Look-aside buffer), a special, small, fast look up hardware cache.
• The TLB is associative, high speed memory.
• Each entry in TLB consists of two parts: a tag and a value.
• When this memory is used, then an item is compared with all tags
simultaneously. If the item is found, then corresponding value is returned.

page replacement strategies In an operating system that uses paging for memory
management, a page replacement algorithm is needed to decide which page
needs to be replaced when a new page comes in.
Page Fault: A page fault happens when a running program accesses a memory
page that is mapped into the virtual address space but not loaded in physical
memory. Since actual physical memory is much smaller than virtual memory, page
faults happen. In case of a page fault, Operating System might have to replace
one of the existing pages with the newly needed page. Different page
replacement algorithms suggest different ways to decide which page to replace.
The target for all algorithms is to reduce the number of page faults.
Page Replacement Algorithms:
1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this
algorithm, the operating system keeps track of all pages in the memory in a
queue, the oldest page is in the front of the queue. When a page needs to be
replaced page in the front of the queue is selected for removal.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page
frames.Find the number of page faults.
Belady’s anomaly proves that it is possible to have more page faults when
increasing the number of page frames while using the First in First Out (FIFO) page
replacement algorithm. For example, if we consider reference strings 3, 2, 1, 0, 3,
2, 4, 3, 2, 1, 0, 4, and 3 slots, we get 9 total page faults, but if we increase slots to
4, we get 10-page faults.

7
3. Least Recently Used: In this algorithm, page will be replaced which is least
recently used.
Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3
with 4 page frames. Find number of page faults.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4
Page faults 0 is already their so —> 0 Page fault. when 3 came it will take the
place of 7 because it is least recently used —>1 Page fault
0 is already in memory so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are
already available in the memory.
4. Most Recently Used (MRU): MRU stands for Most Recently Used, which is a
concept in computer science and refers to a list or record of the items or
elements (files, documents, etc.) that were recently used or accessed. This is
typically used in software applications to provide quick access to frequently used
items, as well as to keep track of a user's activity. MRU is often used to improve
user efficiency and experience by reducing the time spent searching for
frequently used items.
Not Recently Used (NRU):It is a page replacement algorithm. This algorithm
removes a page at random from the lowest numbered non-empty class. Implicit in
this algorithm is that it is better to remove a modified page that has not been
referenced in atleast one clock tick than a clean page that is in heavy use.It is easy
to understand, moderately efficient to implement and gives a performance that
while certainly not optimal, may be adequate. When page is modified, a modified
bit is set. When a page needs to be replaced, the Operating System divides pages
into 4 classes.
0:- Not Referenced, Not Modified
1:- Not Referenced, Modified
2:- Referenced, Not Modified
3:- Referenced, Modified
Out of above 4 categories, NRU will replace a Not Referenced, Not Modified page,
if such page exists. Note that this algorithm implies that a Modified but Not
Referenced is less important than a Not Modified and Referenced.

8
LFU (Least Frequently Used) is a cache replacement policy used in operating
systems to manage memory. It replaces the least frequently used items in the
cache. The idea behind this is that if an item hasn't been used often, it's unlikely
to be used in the future. LFU keeps track of the frequency of use of each item in
the cache and periodically updates this information. When the cache is full and a
new item needs to be added, the operating system will replace the item that has
been used the least number of times. LFU is often used to improve cache
performance by ensuring that frequently used items are stored in memory and
infrequently used items are evicted. However, it can also result in cache pollution
if the frequency of use of an item changes dynamically.

MFU (Most Frequently Used) is a cache replacement policy used in operating


systems to manage memory. It replaces the most frequently used items in the
cache. This policy assumes that frequently used items are likely to be used again
in the future. MFU keeps track of the frequency of use of each item in the cache
and periodically updates this information. When the cache is full and a new item
needs to be added, the operating system will replace the item that has been used
the most number of times. MFU is often used to improve cache performance by
ensuring that frequently used items are stored in memory and infrequently used
items are evicted. However, it can lead to cache thrashing if a small set of items
are used very frequently, causing the cache to constantly remove and re-add the
same items.

MRU (Most Recently Used) is a cache replacement policy used in operating


systems to manage memory. It replaces the item that was least recently used in
the cache. The idea behind this is that items that were recently used are more
likely to be used again in the future compared to items that were used a long time
ago. MRU keeps track of the recent usage of each item in the cache and
periodically updates this information. When the cache is full and a new item
needs to be added, the operating system will replace the item that was used least
recently. MRU is often used to improve cache performance by ensuring that
recently used items are stored in memory and items that were used a long time
ago are evicted. However, it can result in poor performance if the usage patterns
of items change dynamically over time.

9
Allocation and de-allocation are two fundamental concepts in memory
management in operating systems.
Allocation refers to the process of assigning a portion of memory to a program or
process for it to use. This is typically done by the operating system using various
allocation techniques, such as:
• First-fit: Allocates the first block of free memory that is large enough to
fulfill the request.
• Best-fit: Allocates the smallest block of free memory that is large enough to
fulfill the request.
• Worst-fit: Allocates the largest block of free memory that is still large
enough to fulfill the request.
De-allocation refers to the process of releasing memory that is no longer being
used by a program or process, so it can be made available for other programs or
processes to use. This is typically done by the operating system using various de-
allocation techniques, such as:
Coalescing: Merges adjacent free blocks of memory to reduce fragmentation.
Buddy System: Manages memory by dividing it into blocks of a fixed size and
keeping track of which blocks are in use and which are free.
The choice of allocation and de-allocation techniques depends on the
requirements and constraints of the operating system and the specific system
architecture.
Coherence is a concept in computer science that refers to the consistency and
synchronization of shared data in a multi-processor system. A coherence
technique is a method used to ensure that multiple processors in a system have a
consistent view of shared data.
There are several coherence techniques that are commonly used in computer
systems, including:
• Cache Coherence: Enforces the consistency of data across multiple caches
in a multi-processor system.
• Directory-based Coherence: Maintains a directory that keeps track of the
status of shared data and provides information to processors about the
current state of the data.
• Snooping Coherence: Uses a broadcast protocol to monitor the activity of
processors and ensure that the data in their caches is consistent.

10
• Hardware Coherence: Implements coherence through hardware
mechanisms, such as bus snooping or directory-based protocols.
The choice of coherence technique depends on the requirements and constraints
of the specific system architecture. For example, some systems may prioritize low
latency and high performance, while others may prioritize low overhead and ease
of implementation.

UNIT-2
Introduction :
Job is work that needs to be done.
A task is a piece of work that needs to be done.
The process is a series of actions that is done for a particular purpose.
Job and task define the work to be done, whereas process defines the way the
work can be done or how the work should be done.
PROCESS :
The process is a program under execution. A program can be defined as a set of
instructions.
The program is a passive entity and the process is an active entity. When we
execute a program, it remains on the hard drive of our system and when this
program comes into the main memory it becomes a process.
The process can be present on a hard drive, memory or CPU.
A process goes through many states when it is executed. Some of these states are
start, ready, running, waiting or terminated/executed. These names aren’t
standardized. These states are shown in the Process state transition diagram or
process life cycle.
More than one process can be executed at the same time. When multiple
processes are executed at the same time, it needs to be decided which process

11
needs to be executed first. This is known as scheduling of a process or process
scheduling. Thus, a process is also known as a schedulable and executable unit.
A process has certain attributes a”d a process also has a process memory.
Attributes of process are process id, process state, priority, etc.
A process memory is divided into 4 sections – text section, data section, heap and
stack.
The process also facilities interprocess communication. When multiple processes
are executed, it is necessary for processes to communicate using communication
protocols to maintain synchronization.
To further dive into details of the process, you may refer to – Introduction of
process management.
JOB :
A job is a complete unit of work under execution. A job consists of many tasks
which in turn, consist of many processes. A job is a series of tasks in a batch
mode. Programs are written to execute a job.
Job is also obscure as it too holds many meanings. Jobs and tasks are used
synonymously in computational work.
These tasks are further executed in small processes. The task of taking input has a
number of processes involved. First of all, the user enters the information. Then
that information is converted to binary language. Then that information goes to
the CPU for further execution. Then the CPU performs necessary actions to be
taken. Hence, a job is broken into tasks and these tasks are executed in the form
of processes.
A job may be one job at a time or multiple jobs at a time. A single job can be
called a task. To perform multiple jobs at a time a job needs to be scheduled. A
job scheduler is a kind of application program that schedules jobs. A job
scheduling is also known as batch scheduling.
The concept of job, process and task revolves around each other. Job, task and
process may be considered the same or different in reference to the context they
refer to. A process is an isolated entity of Operating System. A task may be called

12
a process if it is a single task. A job may be called a task if the job to be performed
is a single unit of work. A process or group of processes can be termed as a task
and a group of tasks can be termed as a job.
CPU input-output (I/O) interleaving refers to the process of alternating between
CPU and I/O operations in a computer system to maximize the overall efficiency
and utilization of both the CPU and I/O devices. This allows multiple tasks to be
performed simultaneously and reduces waiting times for I/O operations,
improving the overall system performance.In the interleaved I/O process, the CPU
sends a request to the I/O controller to start an I/O operation, then switches to
execute other tasks while the I/O operation is being performed. This allows the
CPU to continue working on other tasks instead of waiting idle for I/O operations
to complete. When the I/O operation is finished, the I/O controller sends an
interrupt to the CPU, which then resumes processing the data. This process of
interleaving I/O operations and CPU execution can help to reduce I/O wait times
and improve overall system responsiveness.
Preemptive refers to a scheduling method where a task can be temporarily
interrupted by the system and replaced by another task with higher priority. This
allows the operating system to efficiently allocate processing time to the most
important tasks and meet deadlines. The process of interrupting a task is known
as preemption. In a preemptive scheduling system, tasks are assigned priorities,
and the task with the highest priority is executed until it is blocked or preempted
by a higher priority task. This helps to ensure that important tasks are completed
in a timely manner, and can improve system stability and responsiveness.
Non-preemptive scheduling is a method of task scheduling where once a task has
started execution, it continues to run until it is completed or blocked. In a non-
preemptive system, the operating system does not interrupt a running task to
allow another task with a higher priority to execute. Instead, the task with the
highest priority is executed only after the currently running task has completed or
been blocked. This type of scheduling is often used in batch processing systems,
where tasks are executed one after the other, and in single-tasking systems,
where only one task is executed at a time. Non-preemptive scheduling can
simplify system design and reduce overhead, as the operating system does not
need to constantly monitor task priorities. However, this method of scheduling

13
can lead to decreased system responsiveness, as tasks with lower priority may
block tasks with higher priority for an extended period of time.
context switching is the process of storing the current state of a task and
restoring the state of another task. This allows the operating system to switch
between multiple tasks, giving the appearance that they are executing
simultaneously. During a context switch, the operating system saves the current
state of the task, including the contents of its registers, memory, and program
counter. The operating system then restores the state of another task and
resumes its execution. This process occurs repeatedly, allowing the operating
system to allocate processing time to multiple tasks and improving system
responsiveness and throughput. The overhead of context switching is dependent
on the operating system implementation, but generally includes the time
required to save and restore task states, and the time required to switch between
tasks. Minimizing context switching overhead is an important consideration in the
design of high-performance systems.
A scheduling algorithm Is a method used by an operating system to determine
which task to execute next, and how long the task should run. Scheduling
algorithms are used to allocate processing time to tasks, and determine which
tasks are executed and in what order.
There are several different types of scheduling algorithms, including:
1. First-Come-First-Served (FCFS)
2. Shortest-Job-First (SJF)
3. Priority Scheduling
4. Round Robin
5. Multilevel Queue Scheduling
6. Multilevel Feedback Queue Scheduling
Each scheduling algorithm has its own strengths and weaknesses, and the choice
of algorithm depends on the specific requirements of the system. For example,
real-time systems may use a priority-based scheduling algorithm, while
interactive systems may use a time-sharing algorithm such as Round Robin.

14
First-Come-First-Served (FCFS) is a scheduling algorithm in which tasks are
executed in the order in which they are received by the operating system. Tasks
are executed in a queue, and the task at the head of the queue is executed first.
In FCFS scheduling, tasks are executed in the order they are received, without
regard to their computational requirements or priority. This can result in a lower
overall system throughput, as tasks with high computational requirements can
block tasks with lower requirements for an extended period of time.
However, FCFS scheduling is simple to implement, and is often used in batch
processing systems where tasks are executed one after the other. Additionally,
FCFS scheduling is often used in systems where task order is important, such as in
disk scheduling, where the order in which disk blocks are accessed affects disk
performance
Shortest-Job-First (SJF) is a scheduling algorithm in which tasks are executed in
order of their computational requirements, or burst time. Tasks with the shortest
burst time are executed first, and longer tasks are executed later.
In SJF scheduling, tasks are assigned a priority based on their burst time, and the
task with the lowest burst time is executed first. This results in a higher overall
system throughput, as tasks with high computational requirements are executed
more quickly, allowing the system to allocate processing time to other tasks.
SJF scheduling can be either preemptive or non-preemptive. In preemptive SJF
scheduling, a running task can be interrupted and replaced by a task with a
shorter burst time. In non-preemptive SJF scheduling, once a task starts
executing, it cannot be interrupted.
Srtf Shortest Remaining Time First (SRTF) is a scheduling algorithm that is similar
to Shortest-Job-First (SJF) scheduling, but with the addition of preemption. In
SRTF scheduling, the task with the shortest remaining time is executed first,
allowing the operating system to switch to a different task if its burst time
decreases.
SRTF scheduling is a preemptive version of SJF scheduling, in which the task with
the shortest remaining time is executed until it completes or until a task with a
shorter remaining time becomes available. This allows the operating system to

15
respond quickly to changes in task requirements and to allocate processing time
more efficiently.
SRTF scheduling is often used in real-time systems where response time is critical,
as it minimizes the amount of time a task spends waiting in the ready queue.
However, SRTF scheduling can result in a higher context switching overhead, as
the operating system must frequently switch between tasks.
Priority scheduling is a scheduling algorithm in which each task is assigned a
priority value, and tasks with higher priority values are executed before tasks with
lower priority values. In priority scheduling, tasks are assigned a priority based on
their computational requirements, criticality, or importance, and the task with the
highest priority is executed first. Priority scheduling can be either preemptive or
non-preemptive. In preemptive priority scheduling, a running task can be
interrupted and replaced by a task with a higher priority. In non-preemptive
priority scheduling, once a task starts executing, it cannot be interrupted.
Priority scheduling is often used in real-time systems, as it allows the operating
system to allocate processing time to critical tasks with high priority, and to
minimize the amount of time that these tasks spend waiting in the ready queue.
However, priority scheduling can result in lower priority tasks being starved, as
they may never be executed if there are always higher priority tasks
Round Robin is a scheduling algorithm used in computer multitasking, where
each task is assigned a fixed time slot in a cyclic order. In Round Robin scheduling,
the operating system allocates a fixed time slice, called a time quantum, to each
task in the ready queue. Once a task’s time quantum expires, it is moved to the
end of the queue, and the next task in the queue is executed.
Round Robin scheduling is a preemptive algorithm, as the operating system can
interrupt a running task if its time quantum expires. This allows the operating
system to allocate processing time to each task in the ready queue, ensuring that
all tasks make progress.
Round Robin scheduling is often used in time-sharing systems, as it provides a
good balance between efficient use of processing time and fair allocation of
processing time to all tasks. However, context switching overhead can be high in

16
Round Robin scheduling, as the operating system must frequently switch between
tasks
Multilevel Queue Scheduling is a scheduling algorithm used in computer
multitasking, where tasks are assigned to different priority levels, or queues,
based on their computational requirements, criticality, or importance. In
Multilevel Queue Scheduling, each queue has its own scheduling algorithm, and
tasks are assigned to a queue based on their priority.
The advantage of Multilevel Queue Scheduling is that it allows the operating
system to allocate processing time more efficiently to tasks with different priority
levels. For example, critical tasks can be assigned to a higher priority queue and
executed using a more efficient scheduling algorithm, while less critical tasks can
be assigned to a lower priority queue and executed using a less efficient, but
fairer, scheduling.
Multilevel Feedback Queue Scheduling is a scheduling algorithm used in
computer multitasking, where tasks are assigned to different priority levels, or
queues, based on their computational requirements, criticality, or importance. In
Multilevel Feedback Queue Scheduling, each queue has its own scheduling
algorithm, and tasks can move between queues based on their behavior.
The advantage of Multilevel Feedback Queue Scheduling is that it allows the
operating system to allocate processing time more efficiently to tasks with
different priority levels. For example, tasks that frequently switch between the
ready and running states can be assigned to a lower priority queue, while tasks
that make steady progress can be assigned to a higher priority queue.
The creation of a PCB Is part of the process management in the operating system.
When a new process is created, the operating system allocates memory for the
process, creates a PCB for the process, and initializes the information in the PCB.
This information includes:
• Process ID (PID): a unique identifier for the process
• Processor state: the current state of the process, such as running, blocked,
or waiting
• Processor register values: the values stored in the processor registers when
the process is suspended

17
• CPU scheduling information: information used by the scheduling algorithm,
such as priority level or time slice
• Memory management information: information used by the memory
manager, such as the memory address space used by the process
• I/O status information: information about the process’s I/O operations,
such as open files or devices
The operating system uses the information in the PCB to manage the process,
allocate resources to the process, and switch between processes. The information
in the PCB is updated as the process moves from one state to another and as the
process uses system resources.
In terms of combining scheduling schemes, the operating system can use different
scheduling algorithms for different processes, or groups of processes, based on
their computational requirements, criticality, or importance. For example, a
system with critical real-time processes can use a combination of Real-Time
scheduling algorithms, such as Earliest Deadline First or Rate Monotonic, while a
general-purpose system can use a combination of algorithms such as Multilevel
Feedback Queue or Round Robin.
The process view In an operating system refers to the representation of a process
in the operating system’s data structures and how it appears to the system’s
users. A process view includes the following information:
1. Process ID (PID): a unique identifier for the process
2. Processor state: the current state of the process, such as running, blocked,
or waiting
3. Processor register values: the values stored in the processor registers when
the process is suspended
4. CPU scheduling information: information used by the scheduling algorithm,
such as priority level or time slice
5. Memory management information: information used by the memory
manager, such as the memory address space used by the process
6. I/O status information: information about the process’s I/O operations,
such as open files or devices
7. Account information: information about the user account associated with
the process, such as user name, group ID, and resource usage information.

18
A process view provides a snapshot of a process’s state and resources at a given
moment in time. This information is used by the operating system to manage
processes and allocate resources, and by system administrators and users to
monitor and control processes.
A thread is a lightweight unit of execution within a process that can run
concurrently with other threads within the same process. Threads share the same
memory and resources as the process that contains them, and they can
communicate and synchronize with each other using various mechanisms.
Inter-Process Communication (IPC) refers to the mechanisms by which different
processes can communicate and exchange data with each other. IPC provides a
way for processes to coordinate and share resources, and to communicate with
each other to achieve a common goal.
There are several types of IPC mechanisms, including:
1. Pipes: unidirectional communication channels that allow data to be sent
from one process to another.
2. Sockets: a low-level, network-based mechanism for communication
between processes on different machines.
3. Message Queues: a mechanism for passing messages between processes,
with optional priority and persistence.
4. Shared Memory: a mechanism for sharing memory between processes,
allowing data to be shared between processes without copying.
5. Semaphores: a mechanism for synchronizing access to shared resources
between processes.
The choice of IPC mechanism depends on the requirements of the application,
such as the type and volume of data to be exchanged, the required reliability, and
the need for synchronization between processes.
Threads and IPC are important mechanisms in modern operating systems, as they
provide a way for applications to perform multiple tasks in parallel, to coordinate
and communicate with each other, and to share resources. This allows
applications to be more responsive, scalable, and efficient, and to provide a
better user experience.

19
UNIT-3
Atomic instructions are used in operating systems (OS) to synchronize access
to shared resources and prevent race conditions. They are crucial for ensuring the
consistency and integrity of shared data structures and to protect critical sections
of code from being simultaneously executed by multiple threads. Atomic
instructions are typically used in multi-threaded environments to ensure that only
one thread at a time can access shared data. This can be done through the use of
locks, semaphores, or other synchronization mechanisms that are implemented
using atomic operations. Here are a few more details about the use of atomic
instructions in OS:
• Implementing synchronization mechanisms: Atomic instructions can be
used to implement synchronization mechanisms like locks, semaphores,
and spinlocks that are used to protect shared resources.
• Memory barriers: Atomic instructions can also be used to enforce memory
barriers that ensure that memory operations are performed in a specific
order, preventing data races and other synchronization issues.
• Inter-process communication: Atomic instructions are also used in inter-
process communication (IPC) to ensure that shared data structures are
updated atomically, avoiding race conditions and other synchronization
issues.
• Concurrent data structures: Atomic instructions are used in the
implementation of concurrent data structures like queues and stacks,
which allow multiple threads to access shared data structures
simultaneously.
Locks in operating systems are synchronization primitives used to control
access to shared resources by multiple threads or processes. They enforce mutual
exclusion, meaning that only one thread can access the shared resource at a time.
Locks can be implemented using semaphores, monitors, or other synchronization
constructs. When a thread acquires a lock, it gains exclusive access to the shared
resource and other threads are blocked until the lock is released. This ensures
that the shared resource is accessed in a controlled and predictable manner,
avoiding race conditions and other synchronization issues. Locks can be
implemented in various ways, such as spinlocks, mutexes, and reader-writer locks,

20
each with its own trade-offs and use cases. Locks can be implemented in
different ways to meet the needs of different use cases. For example:
1. Spinlocks: A spinlock busy-waits (spins) until the lock is acquired. It is
efficient when the lock is held for a short time, but can consume a lot of
CPU cycles if the lock is held for a long time.
2. Mutexes (Mutual Exclusion): A mutex is a lock that can be owned by only
one thread at a time. When a thread acquires a mutex, it blocks all other
threads from acquiring the same lock until it releases it.
3. Reader-Writer Locks: A reader-writer lock allows multiple readers to access
a shared resource simultaneously, but only one writer can access it at a
time. This type of lock is useful in scenarios where multiple readers can
access a shared resource simultaneously, but writers must have exclusive
access.
Spinlocks are a type of lock used in operating systems to synchronize access to
shared resources among multiple threads or processes. They enforce mutual
exclusion by busy-waiting (spinning) until the lock is acquired. The idea is that the
thread repeatedly checks the lock state until it becomes available, and then
acquires it. Spinlocks are efficient when the lock is held for a short time, as they
do not incur the overhead of blocking and unblocking threads. However, if the
lock is held for a long time, the spinning thread can consume a lot of CPU cycles,
leading to performance degradation. Spinlocks are typically used in low-level
system programming, such as the kernel of an operating system, where the cost
of blocking a thread is high and the lock is expected to be held for a short time.
They are also used in real-time systems where the responsiveness of the system is
critical and the cost of blocking a thread is not acceptable.

Mutexes and semaphores are two types of synchronization primitives used in


operating systems to coordinate access to shared resources among multiple
threads or processes.
Mutex (Mutual Exclusion): A mutex is a lock that can be owned by only one
thread at a time. When a thread acquires a mutex, it blocks all other threads from
acquiring the same lock until it releases it. Mutexes are used to enforce mutual
exclusion, meaning that only one thread can access a shared resource at a time.

21
Semaphore: A semaphore is a variable used to control access to a shared
resource. Unlike a mutex, a semaphore can have a value greater than 1, allowing
multiple threads to access the shared resource simultaneously. Semaphores are
used to enforce synchronization between threads or processes and to coordinate
access to shared resources. Both mutexes and semaphores are used to
synchronize access to shared resources and prevent concurrent access that could
lead to data corruption or unexpected behavior. The choice between using a
mutex or a semaphore depends on the specific requirements of the application
and the resources being protected.

Counting semaphores are a type of semaphore used in operating systems to


coordinate access to shared resources among multiple threads or processes.
Unlike binary semaphores, which can only have a value of 0 or 1, counting
semaphores can have a value greater than 1, representing the number of
available resources. The producer-consumer problem is a classic synchronization
problem in which a producer thread generates items and a consumer thread
consumes them. To ensure that the consumer does not attempt to consume
items before they are produced, and that the producer does not produce items
when the buffer is full, a synchronization mechanism is required.
Counting semaphores can be used to solve the producer-consumer problem by
representing the number of available items in the buffer. The semaphore is
initialized to the maximum number of items that the buffer can hold. The
producer decrements the semaphore each time it adds an item to the buffer, and
the consumer increments the semaphore each time it removes an item. When the
semaphore value is 0, the buffer is full and the producer must wait until the
consumer consumes an item. When the semaphore value is equal to the
maximum buffer size, the buffer is empty and the consumer must wait until the
producer produces an item.

Classic synchronization problems are problems in computer science and


operating systems that involve coordinating access to shared resources among
multiple threads or processes. Some of the most well-known classic
synchronization problems include:

22
1. Producer-Consumer Problem: A producer thread generates items and a
consumer thread consumes them. The goal is to ensure that the consumer
does not attempt to consume items before they are produced, and that the
producer does not produce items when the buffer is full.
2. Readers-Writers Problem: Multiple readers can access a shared resource
simultaneously, but only one writer can access the resource at a time. The
goal is to ensure that multiple readers can access the resource
simultaneously, but that writers have exclusive access when they need to
modify the resource.
3. Dining Philosophers Problem: Five philosophers are seated around a table
and must share chopsticks to eat. The goal is to ensure that each
philosopher can eat without deadlocking or starving.
4. Sleeping Barber Problem: A barber has a barber shop with a waiting room
for customers. The goal is to ensure that the barber serves customers in the
order in which they arrive, and that customers do not leave the shop if the
barber is sleeping.
These classic synchronization problems are often used as examples to illustrate
the importance of proper synchronization in multi-threaded or multi-process
systems, and to demonstrate the use of synchronization primitives such as locks,
semaphores, and monitors to coordinate access to shared resources.

Monitors and condition variables are two related concepts in computer science
and operating systems that are used to coordinate access to shared resources
among multiple threads or processes.
• Monitors: A monitor is a synchronization construct that provides a
centralized mechanism for coordinating access to shared resources.
Monitors are typically used in object-oriented programming languages and
provide a way to encapsulate data and the operations that can be
performed on that data. Monitors enforce mutual exclusion, meaning that
only one thread can access a shared resource at a time.
• Condition Variables: Condition variables are a mechanism used within
monitors to allow threads to wait for a specific condition to become true.
When a thread encounters a condition that must be met before it can
continue, it can wait on a condition variable. The thread is then blocked
until another thread signals the condition variable, indicating that the

23
condition has been met. When the condition variable is signaled, the
waiting thread is unblocked and can continue executing.
Condition variables are used in conjunction with monitors to provide a way for
threads to wait for specific conditions to be met before continuing. For example,
in a producer-consumer problem, the consumer thread might wait on a condition
variable until the producer has produced an item. The producer then signals the
condition variable, indicating that an item is available, and the consumer is
unblocked and can consume the item. By using condition variables in conjunction
with monitors, it is possible to coordinate access to shared resources and ensure
that threads are only unblocked when the conditions they are waiting for are met,
avoiding race conditions and other synchronization issues.

Message passing is a technique for coordinating access to shared resources


among multiple threads or processes in a distributed system. It can be used to
solve classic synchronization problems, such as the producer-consumer problem,
the dining philosophers problem, the readers-writers problem, and the sleeping
barber problem.
1. Producer-Consumer Problem: In a message passing solution to the
producer-consumer problem, the producer and consumer communicate
with each other by sending messages. The producer sends a message to the
consumer indicating that it has produced an item, and the consumer sends
a message to the producer indicating that it has consumed an item. This
allows the producer and consumer to coordinate their actions and ensure
that the consumer does not attempt to consume items before they are
produced, and that the producer does not produce items when the buffer is
full.
2. Dining Philosophers Problem: In a message passing solution to the dining
philosophers problem, the philosophers communicate with each other by
sending messages to request access to the chopsticks. When a philosopher
wants to eat, it sends a message to its neighbors indicating that it wants to
use the chopsticks. If both neighbors are not eating, the philosopher is
allowed to eat. This allows the philosophers to coordinate their access to
the chopsticks and avoid deadlocks.
3. Readers-Writers Problem: In a message passing solution to the readers-
writers problem, readers and writers communicate with each other by

24
sending messages. The readers send messages to the writers indicating that
they want to read, and the writers send messages to the readers indicating
that they want to write. This allows the readers and writers to coordinate
their access to the shared resource and ensure that multiple readers can
access the resource simultaneously, but that writers have exclusive access
when they need to modify the resource.
4. Sleeping Barber Problem: In a message passing solution to the sleeping
barber problem, the barber and customers communicate with each other
by sending messages. When a customer enters the barber shop, it sends a
message to the barber indicating that it wants a haircut. If the barber is
awake, it begins cutting the customer's hair. If the barber is sleeping, the
customer wakes the barber and begins cutting the customer's hair. This
allows the barber and customers to coordinate their actions and avoid race
conditions.
Message passing can be used to provide a flexible and scalable solution to classic
synchronization problems. It is well-suited for distributed systems or systems with
a high degree of concurrency, as it allows threads or processes to communicate
and coordinate their actions without the need for a centralized synchronization
mechanism. However, message passing can also be more complex to implement
and debug than other synchronization techniques, such as monitors or
semaphores.

Deadlock: A deadlock is a situation in a computer system where two or more


processes are blocked, waiting for each other to release a resource they need.
This results in a standstill, where none of the processes can continue to execute.
Characteristics:
• Mutual Exclusion: Only one process can use a resource at a time.
• Hold and Wait: A process holds a resource while waiting for another
resource.
• No Preemption: Resources cannot be taken away from a process once they
have been granted.
• Circular Wait: Processes form a circular chain, where each process is
waiting for a resource held by another process in the chain.
Resource Allocation Graph: A resource allocation graph is a graphical
representation of the relationships between processes and resources in a system.

25
It is used to detect deadlocks and analyze the state of a system. In a resource
allocation graph, processes are represented as nodes and resources as edges. A
directed edge from process P to resource R indicates that process P is holding
resource R.
Live-lock: A live-lock is a situation where two or more processes continuously
change their state in response to the state of the other processes, without making
progress. This results in a situation where the processes are active, but not
making progress towards completion.
Deadlock Prevention: Deadlocks can be prevented by avoiding the conditions
that lead to deadlocks, such as mutual exclusion, hold and wait, no preemption,
and circular wait. Some common techniques for deadlock prevention include:
1. Resource ordering: Allocating resources to processes in a specific order, so
that the circular wait condition cannot occur.
2. Timeouts: Setting a timeout for resource requests, so that processes do not
wait indefinitely for a resource.
3. Preemption: Allowing resources to be taken away from a process if it is
waiting for a resource for too long.
4. Detection and Recovery: Detecting deadlocks and taking action to recover
from them, such as aborting one of the processes involved in the deadlock.
Deadlock prevention is an important aspect of system design, as it ensures that
the system remains responsive and that processes can continue to make progress.
Deadlock Avoidance: Deadlock avoidance is a technique for preventing deadlocks
in a computer system by dynamically avoiding conditions that could lead to a
deadlock.
Banker's Algorithm: The Banker's Algorithm is a deadlock avoidance algorithm
that ensures that a system will never enter a deadlock state. It does this by
maintaining a safe state, where all processes can continue to execute, and an
unsafe state, where deadlocks could occur. The algorithm uses a resource
allocation matrix and a maximum resource matrix to determine if a request for
resources by a process can be granted without entering an unsafe state. If a
request can be granted, the resources are allocated to the process. If a request
cannot be granted, the process must wait until the resources become available.
Deadlock Detection and Recovery: Deadlock detection and recovery is a
technique for handling deadlocks in a computer system by detecting deadlocks

26
and taking action to resolve them. Deadlock detection is typically performed by
examining the state of the system and identifying processes that are blocked and
waiting for resources. Once a deadlock is detected, the system must take action
to resolve the deadlock, such as aborting one of the processes involved in the
deadlock or releasing resources that are being held by one of the processes.
Deadlock detection and recovery is a reactive approach to handling deadlocks, as
it only takes action after a deadlock has occurred. In contrast, deadlock avoidance
is a proactive approach, as it prevents deadlocks from occurring in the first place.
Both approaches have their benefits and limitations, and the choice of which to
use depends on the requirements of the system being designed.

Threads: A thread is a lightweight, independent unit of execution within a


process. Threads share the same address space and system resources as the
process that created them, but they have their own stack, program counter, and
register values.
Thread Basics and Advantages: Threads provide a way for a process to execute
multiple tasks concurrently, which can improve the performance and
responsiveness of a system. Threads have several advantages, including increased
parallelism, reduced overhead, and improved resource utilization. By executing
multiple tasks concurrently, threads can increase the overall throughput of a
system and reduce the time required to complete a task. Additionally, threads can
improve the responsiveness of a system by allowing it to continue processing
other tasks while waiting for a blocking operation to complete.

Multicore programming is the practice of writing software that can take


advantage of multiple cores or processors within a single computer. The goal is to
improve the performance of the software by dividing the workload among
multiple cores.
Amdahl's Law is a mathematical formula that helps predict the theoretical
maximum speedup that can be achieved by parallelizing a task. It states that the
speedup is limited by the fraction of the task that must be executed sequentially.
This means that even if a task is parallelized, there will still be some portion of the
task that must be performed on a single core, and the overall speedup will be
limited by this portion of the task.

27
Multicore programming presents several challenges including:
• Synchronization and coordination between parallel tasks.
• Data sharing and communication between parallel tasks.
• Load balancing and distribution of work among parallel tasks.
• Debugging and testing parallel code.
There are several types of parallelism:
• Data Parallelism: dividing the data set into smaller parts and processing
each part in parallel.
• Task Parallelism: dividing a single task into smaller sub-tasks that can be
executed in parallel.
• Instruction-Level Parallelism: exploiting instruction-level parallelism within
a single thread to improve performance.
• Pipeline Parallelism: breaking down a task into stages, each of which can be
executed in parallel with other stages.
Multithreading models refer to the ways in which multiple threads can be
created, managed, and executed in parallel. Some common multithreading
models include:
• Thread-per-Task Model: Each task is assigned its own thread, which runs
independently from other threads.
• Pool of Threads Model: A fixed number of threads are created and reused
to execute multiple tasks.
• Work-Stealing Model: A dynamic pool of threads is used, with idle threads
"stealing" work from other threads that are busy.
• Cooperative Multithreading: Multiple threads are executed together, with
each thread voluntarily yielding control to other threads.
• Asynchronous Multithreading: Multiple threads are executed
asynchronously, with each thread executing independently of the others.
• Master-Worker Model: A single master thread creates and manages
multiple worker threads.
• Barrier Synchronization Model: Multiple threads are synchronized at
specific points, known as barriers, to ensure that they are all working
together correctly.

28
• Task Parallelism Model: Tasks are divided and executed in parallel, with
threads being created and managed dynamically as needed.
• Fine-Grained Multithreading: Multiple threads are created and executed
with very small granularity, with the goal of maximizing parallelism.
• NUMA (Non-Uniform Memory Access) Model: Multiple threads access
memory in a way that is optimized for the underlying hardware, with the
goal of improving performance.
OpenMP (Open Multi-Processing) is a thread library for shared memory
architecture, which provides a standardized API for creating and managing
parallel threads in a shared memory environment.
The OpenMP fork-join model consists of a master thread that forks a team of
worker threads to perform parallel tasks, and then joins the worker threads back
to the master thread. The worker threads execute the same code as the master
thread, but on different data.
OpenMP provides several directives and programming constructs to control
parallel execution, including:
• Schedule: Specifies how the work is divided among threads. OpenMP
supports several types of schedules, such as static, dynamic, and guided.
• Parallel: Specifies the start of a parallel region, with the goal of executing
the code within the region in parallel.
• For: Specifies a loop that should be executed in parallel.
• Sections: Specifies multiple sections of code that should be executed in
parallel.
• Single: Specifies that a block of code should be executed by a single thread.
• Barrier: Specifies a synchronization point where all threads must wait
before continuing.
• Critical: Specifies a block of code that should be executed by a single thread
at a time.
• Atomic: Specifies a block of code that should be executed atomically,
without being interrupted by other threads.
Pthreads (Posix Threads) is a popular library for multithreaded programming,
which provides a standardized API for creating and managing threads in a wide
range of operating systems.

29
Basic programming constructs of Pthreads include:
1. pthread_create: Creates a new thread.
2. pthread_join: Waits for a thread to complete and retrieves its exit status.
3. pthread_exit: Exits from a thread and returns a status.
4. pthread_cancel: Cancels a thread.
In Pthreads, implicit threading refers to the automatic creation of threads by the
operating system, such as when a program is executing multiple tasks
simultaneously. Explicit threading refers to the explicit creation of threads by a
programmer, using Pthreads API.
Common threading issues in Pthreads include:
1. Deadlocks: When multiple threads are waiting for each other, resulting in a
deadlock.
2. Race conditions: When multiple threads access shared data
simultaneously, resulting in unpredictable behavior.
3. Starvation: When a thread is prevented from executing due to a lack of
resources.
4. Priority inversion: When a high-priority thread is blocked by a low-priority
thread, resulting in a lower overall performance.
To avoid these issues, Pthreads provides several synchronization mechanisms,
such as mutexes and condition variables, to control access to shared data and
ensure that threads work together correctly.

UNIT-4

I/O (input/output) management refers to the process of controlling and


coordinating the transfer of data to and from a computer's storage devices (such
as hard drives) and its peripheral devices (such as keyboard, mouse, printers). It
ensures that data is efficiently transferred and prevents data loss or corruption.
I/O management is an important aspect of operating systems and is responsible
for handling the flow of data and maximizing the performance of I/O devices. I/O
management also involves error handling, prioritizing and scheduling I/O
requests, buffering and caching data, and managing the device drivers. It also

30
ensures data consistency by using techniques such as locking and synchronization.
The I/O management system is optimized for performance and reliability, and it is
transparent to the user. The implementation of I/O management varies between
operating systems, but its goal remains the same: to provide a fast and reliable
transfer of data between the computer and its devices.
I/O buffering refers to the process of temporarily storing data in memory before
it is written to a permanent storage device (e.g., hard disk). This improves the
performance of I/O operations by reducing the number of disk accesses and by
allowing multiple I/O requests to be combined into a single disk access. The use of
I/O buffering can also increase reliability by allowing the operating system to retry
failed I/O operations, and by providing a way to handle hardware errors. In I/O
buffering, data is stored in a buffer, which is a reserved area of memory. When an
I/O operation is performed, data is transferred from the buffer to the storage
device. When data is read from the storage device, it is temporarily stored in the
buffer before being returned to the requesting process. The use of I/O buffering
can significantly improve the performance of I/O operations, particularly when
dealing with large amounts of data.
Single buffering and double buffering are two schemes used for I/O buffering.
Single buffering is a scheme in which a single buffer is used to temporarily store
data before it is written to a permanent storage device. This scheme is simple and
efficient, but it can lead to data loss if an error occurs during the transfer of data
from the buffer to the storage device. Double buffering, on the other hand, uses
two buffers. While data is being transferred from one buffer to the permanent
storage device, the other buffer is used to store incoming data. This scheme
provides a higher degree of reliability as it ensures that data is never lost, even if
an error occurs during a transfer. Additionally, double buffering can improve the
performance of I/O operations by allowing the operating system to overlap the
transfer of data with the processing of incoming data. Both single buffering and
double buffering have their own advantages and disadvantages, and the choice of
scheme depends on the specific requirements of the system.

31
Disk organization refers to the way data is structured and stored on a disk drive.
There are several methods of disk organization, including:
• MBR (Master Boot Record): It is the first sector of a disk that contains
information about the disk's partition table and the location of the
operating system's boot loader.
• GPT (GUID Partition Table): A newer alternative to MBR that supports
larger disk sizes and more partitions.
• Partitioning: The disk is divided into multiple logical partitions, each of
which appears as a separate disk drive to the operating system.
• File systems: The method used to organize and manage files and
directories on a disk. Examples include NTFS, FAT32, and ext4.
• Clustering: The method used to allocate disk space to individual files. Files
are stored as a series of clusters, with each cluster representing a block of
disk space.
• Indexing: The method used to keep track of the location of files on a disk.
An index is used to associate each file with the disk clusters that store its
data.
The disk organization method used depends on the requirements of the system
and the operating system being used. The goal of disk organization is to provide
efficient access to data and to ensure data consistency and integrity.

File management refers to the techniques and processes used to manage and
organize files and directories on a computer's storage devices. This includes
creating, storing, and retrieving files; managing file permissions; and maintaining
the file system.
The main tasks of file management include:
• File creation: Creating new files and directories.
• File storage: Storing files in a logical and organized manner on a disk or
other storage device.
• File retrieval: Finding and accessing files quickly and efficiently.
• File organization: Arranging files into a directory structure to make it easier
to find and manage files.
• File backup: Creating copies of files for safekeeping and disaster recovery.
• File compression: Reducing the size of files to save disk space.

32
• File security: Protecting files from unauthorized access and modification.
• The goal of file management is to make it easy to find, access, and manage
files, while ensuring the security and reliability of the data. This is achieved
through the use of file systems, directory structures, and other tools and
techniques.
File concepts refer to the fundamental ideas and principles related to the
creation, organization, and management of files on a computer. Some of the key
concepts in file management include:
• File: A collection of data stored as a single unit, with a unique name and
location.
• Directory (or folder): A container that holds files and other directories.
• Path: The location of a file on a computer, specified by a sequence of
directories and subdirectories.
• File attributes: Characteristics of a file, such as its size, creation date, and
permissions.
• File format: The structure and organization of data within a file. Common
file formats include text files, image files, and audio files.
• File system: The method used to organize and manage files and directories
on a disk. Examples include NTFS, FAT32, and ext4.
• Link (or shortcut): A pointer to a file or directory, which allows it to be
accessed from multiple locations.
• Backup: A copy of a file or set of files, created for disaster recovery or data
preservation.
• Compression: The reduction of file size by encoding data in a more efficient
format.
These concepts form the foundation for file management, and understanding
them is essential for effective file management and organization.

A file descriptor is an abstract index that refers to an open file or other


input/output resource in a computer operating system. It is a non-negative
integer value that the operating system assigns to a file when it is opened. The file
descriptor acts as a handle to the file, and all subsequent I/O operations on the
file are performed using the file descriptor. File descriptors are used by the
operating system to keep track of open files and manage I/O operations. They

33
provide a convenient and efficient way for processes to access files, as the file
descriptor can be passed as a parameter to system calls for reading and writing
data. File descriptors have several properties, including the mode in which the file
was opened (read, write, or read/write), the current position of the file pointer,
and flags indicating the status of the file (e.g., whether the file is a terminal
device). File descriptors are used by many programming languages and libraries,
including the standard I/O library in C and C++, as a way to access and manipulate
files.
Access methods: Sequential
Sequential access is a method of accessing data in a file in a linear, one-record-
after-another manner. In sequential access, data is read from the beginning of the
file to the end, and the access method does not allow for random access to
specific data within the file. Sequential access is typically used for large files, such
as audio or video files, where it is not necessary to access specific data quickly.
This method is also useful for data that is processed in a specific order, such as in
data processing pipelines. One of the main advantages of sequential access is that
it is simple to implement and efficient for reading large amounts of data. The
disadvantages include slower access times for specific data within the file, and the
requirement to read the entire file to access a single piece of data. Sequential
access is supported by many programming languages and libraries, and is typically
used in conjunction with other access methods, such as indexed or direct access,
for a complete solution for file management.

indexed and direct,


Indexed and Direct access are methods of accessing data in a file by directly
referring to the location of the data within the file. These methods are typically
used for smaller files, such as databases, where quick access to specific data is
important. Indexed access uses an index to locate the data. The index contains a
mapping of data values to the physical location of the data within the file. When
data is requested, the index is searched to find the location of the data, and the
data is then retrieved from that location. Direct access uses the physical address
of the data on the storage device to locate the data. In direct access, the file is

34
divided into fixed-size blocks, and the data is stored in a specific block. The
physical address of the block is used to locate the data, and the data is then
retrieved from that location. One of the main advantages of indexed and direct
access is that they allow for quick access to specific data within the file. The
disadvantages include the need for additional data structures, such as the index,
to be maintained, and the potential for data fragmentation, which can impact
performance. Indexed and direct access are supported by many programming
languages and libraries, and are often used in conjunction with other access
methods, such as sequential access, for a complete solution for file management.
File sharing: File sharing refers to the ability of multiple users or systems to access
the same file or files simultaneously. This allows multiple users to collaborate on a
project, or for multiple systems to access the same data, without the need for
multiple copies of the same data. There are several methods for implementing file
sharing, including: Network file sharing: In this method, the file is stored on a
central server and made accessible over a network to multiple users or systems.
Distributed file sharing: In this method, the file is stored across multiple systems
in a distributed fashion, with each system having a portion of the file. The file is
accessed by the combination of the data stored on each system.
Cloud file sharing: In this method, the file is stored on a remote server that is
accessible over the internet, and made available to multiple users or systems. File
sharing has many advantages, including the ability to collaborate on projects, the
ability to access data from multiple locations, and the ability to store large
amounts of data in a centralized manner. The disadvantages include security
concerns, the need for a reliable network, and the potential for data integrity
issues. File sharing is supported by many operating systems and programming
languages, and is often used in conjunction with other access methods, such as
sequential or direct access, for a complete solution for file management.

Protection,
Protection is a feature of file systems that restricts access to files based on user-
defined criteria, such as user identity, access rights, or other factors. The goal of
protection is to ensure the confidentiality, integrity, and availability of data stored
in files. Protection is typically implemented through access control lists (ACLs) or
permissions, which specify the actions that users or systems can perform on the

35
files, such as read, write, or execute. Protection can be applied at various levels,
including at the file system level, at the directory level, or at the individual file
level. Protection has several advantages, including the ability to prevent
unauthorized access to sensitive data, the ability to enforce data retention
policies, and the ability to prevent data tampering or corruption. The
disadvantages of protection include the need for additional management and
administration, the potential for accidental or unintended changes to access
controls, and the need for user training to understand the access controls.
Protection is supported by many operating systems and programming languages,
and is an important aspect of file management in most environments. The
protection mechanisms used will depend on the specific requirements of the
environment and the type of data being stored.
Access rights: Access rights, also known as permissions, are the specific actions
that a user or system is allowed to perform on a file. These actions may include
reading, writing, executing, or deleting the file. Access rights are a key aspect of
protection in file management and are used to restrict access to sensitive data or
to enforce data retention policies. Access rights can be defined at various levels,
including at the file system level, at the directory level, or at the individual file
level. They are typically specified in an access control list (ACL) or through a set of
permissions assigned to the user or system. The assignment of access rights is
usually done by an administrator or a designated user with appropriate privileges.
The access rights for a file can be modified at any time to accommodate changes
in the data or in the environment. Access rights have several advantages,
including the ability to prevent unauthorized access to sensitive data, the ability
to enforce data retention policies, and the ability to prevent data tampering or
corruption. The disadvantages of access rights include the need for additional
management and administration, the potential for accidental or unintended
changes to access controls, and the need for user training to understand the
access controls. Access rights are supported by most operating systems and
programming languages, and are an important aspect of file management in most
environments. The specific access rights used will depend on the specific
requirements of the environment and the type of data being stored.

36
File System structure: File system structure refers to the way in which data is
organized and stored within a file system. The file system structure determines
how files are named, how they are stored, and how they are retrieved. There are
several common file system structures, including:
• Hierarchical file system: In this structure, files and directories are organized
in a tree-like fashion, with a root directory at the top, and subdirectories
branching out from there. This is the structure used by most operating
systems, including Windows and Unix-based systems.
• Flat file system: In this structure, all files are stored in a single directory,
with no subdirectories. This is the simplest form of file system structure.
• Database file system: In this structure, files are organized as records within
a database, with each record containing a set of related data. This structure
is used by some specialized applications, such as financial systems or
medical record systems.
• Cluster file system: In this structure, files are stored across multiple
systems in a distributed fashion, with each system storing a portion of the
data. The file is accessed by the combination of the data stored on each
system. The choice of file system structure will depend on the specific
requirements of the environment and the type of data being stored. The
file system structure can have a significant impact on the performance,
reliability, and scalability of the file system, and it is important to choose
the appropriate structure for the specific needs of the environment.
Byte Sequence: Byte sequence refers to the arrangement of bytes within a file.
Byte sequence determines the order in which the bytes are stored, which can
impact the ability of the file system to retrieve and process the data. There are
two common byte sequences used in computer systems:
• Big-endian: In this byte sequence, the most significant byte (MSB) is stored
first, followed by the next most significant byte, and so on. Big-endian byte
sequence is used by some computer architectures, such as the PowerPC
architecture.
• Little-endian: In this byte sequence, the least significant byte (LSB) is stored
first, followed by the next least significant byte, and so on. Little-endian
byte sequence is used by most computer architectures, including the x86

37
architecture. The choice of byte sequence will depend on the specific
requirements of the environment and the type of data being stored. Byte
sequence can have a significant impact on the performance and
functionality of the file system, and it is important to choose the
appropriate byte sequence for the specific needs of the environment.
Record sequence and Tree-based: Record sequence and tree-based are two
common file organization methods used in file systems.
• Record sequence: In this method, files are organized as a sequence of
records, where each record contains a set of related data. The records are
stored in a linear fashion, with each record following the previous one. This
method is often used in database systems, where the data is organized as a
set of related records.
• Tree-based: In this method, files are organized in a hierarchical fashion,
similar to a tree structure. Each file or directory is a node in the tree, with
subdirectories branching out from parent directories. This method is
commonly used in most file systems, including Windows and Unix-based
systems.The choice of file organization method will depend on the specific
requirements of the environment and the type of data being stored. Record
sequence is often used for data that is best organized as a set of related
records, while tree-based is often used for data that is best organized in a
hierarchical fashion.
Recovery and Disk formatting. Recovery and disk formatting are two important
aspects of file system access methods.
• Recovery: This refers to the ability of the file system to recover from errors
or data loss. A good recovery system can ensure that data is not lost due to
hardware failures, software crashes, or other issues. Recovery methods
may include backup and restore procedures, data redundancy, and error
correction codes.
• Disk formatting: This refers to the process of preparing a disk for use by a
file system. Disk formatting involves creating a file system on the disk,
which involves creating a structure for organizing and storing files and
directories. Disk formatting also involves creating data structures, such as
the boot sector, file allocation tables, and directory entries.

38
Both recovery and disk formatting are important for ensuring the reliability and
performance of the file system. It is important to choose appropriate recovery
and disk formatting methods for the specific needs of the environment, to ensure
that data is protected and that the file system is functioning optimally.

File allocation methods: Contiguous Allocation and Non Contiguous allocation:


File allocation methods refer to the way in which disk space is assigned to files on
a file system. There are two main methods of file allocation: contiguous allocation
and non-contiguous allocation.
Contiguous allocation: In this method, disk space is allocated to a file as a single,
contiguous block. This means that the file is stored as a single sequence of disk
blocks, with no gaps or unused space between blocks. Contiguous allocation
provides efficient access to large files, as the disk head only needs to move in one
direction to read the entire file. However, this method can lead to disk
fragmentation, which occurs when there is not enough contiguous space to
allocate to a file.
Non-contiguous allocation: In this method, disk space is allocated to a file as a
series of separate blocks, with gaps between blocks. This means that the file is
stored as a collection of non-contiguous blocks, rather than a single contiguous
block. Non-contiguous allocation provides greater flexibility in allocating disk
space, as files can be stored in any available space on the disk. This method can
help to reduce disk fragmentation, as files can be allocated to any available space
on the disk. The choice of file allocation method will depend on the specific
requirements of the environment and the type of data being stored. Both
contiguous and non-contiguous allocation have advantages and disadvantages,
and it is important to choose the appropriate file allocation method for the
specific needs of the environment.
Chained,: File allocation methods refer to the way in which disk space is assigned
to files on a file system. One of the methods is Chained allocation.
Chained allocation: This is a method of non-contiguous allocation in which the
blocks that make up a file are linked together in a chain, much like a linked list.
Each block contains a pointer to the next block in the chain, allowing the file
system to access all blocks in the file. Chained allocation is useful for storing files

39
that are frequently growing or changing in size, as it allows the file system to
allocate new blocks to the file as needed. The disadvantage of this method is that
accessing the file requires following the chain of pointers, which can result in slow
access times for large files.
Indexed allocation: This is a method of non-contiguous allocation in which an
index block is used to store the locations of all blocks that make up a file. The
index block acts as a map or table of contents, providing the file system with a
way to access all blocks in the file. Indexed allocation is useful for storing large
files, as it allows the file system to access the file quickly and efficiently, without
having to follow a chain of pointers as in Chained allocation. The disadvantage of
this method is that it requires more disk space to store the index block, and
updating the index block when the file is modified can be time-consuming. Both
Chained and Indexed allocation are methods of non-contiguous allocation, and
the choice between them will depend on the specific requirements of the
environment and the type of data being stored. It is important to choose the
appropriate file allocation method for the specific needs of the environment, to
ensure that disk space is used efficiently and that files can be accessed quickly
and easily.
free space management: Free space management: This refers to the process of
keeping track of the available disk space and allocating it to new files as needed.
When a file is deleted or a block is freed up, the free space management system
marks it as available for reuse. The goal of free space management is to ensure
that disk space is used efficiently, with as little fragmentation as possible, and to
prevent disk space from being wasted. Different file allocation methods may use
different techniques for free space management, such as bit maps, linked lists, or
other data structures to keep track of available disk space. Free space
management is a critical component of any file system, as it ensures that disk
space is used efficiently and that files can be stored and retrieved quickly and
easily. It is important to choose an appropriate free space management strategy
that is well-suited to the specific requirements of the environment, in order to
ensure that disk space is used efficiently and effectively.

40
Disk Scheduling refers to the order in which the disk controller accesses the disk
platters to read or write data. It plays an important role in optimizing disk
performance by reducing disk seek time and rotational latency. Some common
disk scheduling algorithms include:
• FCFS (First-Come, First-Served): The disk arm services requests in the order
in which they are received, without considering the current position of the
disk arm. This algorithm is simple, but can result in long disk arm seek times
and poor disk performance.
• SSTF (Shortest Seek Time First): The disk arm selects the request that is
closest to its current position, in order to minimize the disk seek time. This
algorithm can result in better disk performance compared to FCFS, but can
still lead to long wait times for requests that are located far from the
current disk arm position.
• SCAN (Elevator Algorithm): The disk arm scans the disk platter in one
direction, serving requests in order, until it reaches the end of the disk. It
then reverses direction and scans the disk in the opposite direction, serving
requests in order. This algorithm ensures that all requests are eventually
serviced, but can result in long wait times for requests that are far from the
disk arm's current position.
• C-SCAN (Circular SCAN): Similar to SCAN, but the disk arm scans the disk
platter in one direction, serving requests in order, until it reaches the end
of the disk. It then immediately jumps to the other end of the disk, without
reversing direction, and continues scanning in the same direction. This
algorithm is optimized for disk platters with large numbers of tracks, and
can result in lower average wait times compared to SCAN.
• Disk Cache: A disk cache is a high-speed memory buffer that is used to
temporarily store data that is being read from or written to disk. The disk
cache acts as a buffer between the disk and the main memory, reducing
disk I/O operations and improving disk performance by allowing the disk
controller to operate more efficiently.Each of these disk scheduling
algorithms has its own strengths and weaknesses, and the choice of
algorithm will depend on the specific requirements of the environment and
the type of data being stored. It is important to choose the appropriate disk
scheduling algorithm for the specific needs of the environment, to ensure

41
that disk performance is optimized and that disk I/O operations are
completed as efficiently as possible.

Protection and Security: System performance, Protection and security are critical
concerns in computer systems, as they ensure the confidentiality, integrity, and
availability of data and resources. System performance can be impacted by
protection and security measures, as implementing these measures often
requires additional processing overhead. In order to balance the need for
protection and security with the need for efficient system performance, it is
important to choose appropriate security measures that are proportional to the
risks that the system is facing. For example, a system that stores sensitive
financial data may require stronger security measures and may be willing to
accept a lower level of performance, while a system that provides a public web
interface may require weaker security measures and may prioritize performance
over protection. Additionally, implementing protection and security measures at
the appropriate layer of the system can also help to minimize their impact on
performance. For example, implementing encryption at the network layer can
reduce the overhead associated with encrypting individual transactions, while
implementing encryption at the application layer can result in higher overhead
due to the need to encrypt and decrypt data for each transaction. Ultimately, the
right balance between protection and security and system performance will
depend on the specific requirements and constraints of the system, and will often
involve a trade-off between the two. It is important to carefully consider the
specific risks that the system is facing and to choose appropriate protection and
security measures that balance the need for protection and security with the
need for efficient system performance.
protection and security: Protection and security are critical concerns in computer
systems as they ensure the confidentiality, integrity, and availability of data and
resources. Protection refers to measures that are taken to prevent unauthorized
access to, use of, or modification of data and resources, while security refers to
the overall measures taken to protect the system from various types of threats
and vulnerabilities. There are several types of protection and security measures
that can be taken to ensure the confidentiality, integrity, and availability of data
and resources. These measures can include:

42
• Access control: This refers to the process of granting or denying access to
specific data and resources based on user credentials and permissions.
Access control can be implemented at the operating system, database, or
application level.
• Encryption: This is the process of transforming data into a coded form to
prevent unauthorized access. Encryption can be used to protect data at rest
(when it is stored) or in transit (when it is transmitted over a network).
• Firewalls: This is a network security system that monitors and controls
incoming and outgoing network traffic based on predetermined security
rules. Firewalls are typically placed between the internal network and the
Internet to prevent unauthorized access to the internal network.
• Antivirus/Antimalware: This is software that is designed to detect and
prevent malicious software (malware) from infecting a computer system.
Antivirus and antimalware software can help to prevent data loss, theft, or
damage caused by malware.
• Backup and recovery: This is the process of creating and maintaining a copy
of important data and resources in order to protect against data loss or
corruption. This can include regular backups, disaster recovery plans, and
data redundancy measures. Protection and security are ongoing concerns
in the operation of computer systems and must be regularly reviewed and
updated in response to changing threats and vulnerabilities. The right
balance between protection and security measures and system
performance must be maintained in order to ensure that the system is
secure while still providing an acceptable level of performance.
policies and methods: Policies and methods refer to the specific procedures and
guidelines that are put in place to ensure the protection and security of data and
resources in a computer system. Policies are formal statements that define the
rules and procedures that govern the use and protection of data and resources.
They set clear expectations for users and administrators, and provide guidance on
the measures that are taken to ensure the confidentiality, integrity, and
availability of data and resources. Methods, on the other hand, are the specific
techniques and procedures that are used to implement the policies and achieve
the goals of protection and security. Methods can include access control,
encryption, firewalls, antivirus/antimalware, backup and recovery, and other

43
protection and security measures. In order to effectively protect and secure a
computer system, it is important to develop clear and comprehensive policies and
implement effective methods that are in line with these policies. Regular
monitoring and review of policies and methods are also necessary to ensure that
they are up-to-date and effective in the face of changing threats and
vulnerabilities.
Access Matrix: The Access Matrix is a data structure used in computer security to
represent the permissions and access rights that users have to objects in a
system. An object can be anything in the system such as a file, a process, a
memory address, etc. The matrix is a table with rows representing subjects (e.g.
users, processes) and columns representing objects. Each cell in the table
represents the access rights of a particular subject to a particular object. The
access rights can be defined in terms of operations, such as read, write, execute,
etc. The Access Matrix provides a clear and efficient representation of the access
control policies in a system. It is used to enforce the policies and to ensure that
users can only access objects for which they have the appropriate permissions.
The Access Matrix is a fundamental concept in computer security and is widely
used in operating systems, database management systems, and other security-
critical software.

44
UNIT-5
The history of Linux can be traced back to the late 1980s and early 1990s. Linus
Torvalds, a student at the University of Helsinki, began developing a new
operating system as a hobby project. He wanted to create a free and open-source
alternative to the proprietary operating systems that were widely used at the
time. In 1991, Torvalds released the source code for his operating system, which
he named Linux, under the GPL (General Public License). This made it possible for
anyone to use, modify, and redistribute the code as they wished.Over the next
several years, Linux rapidly gained popularity among developers and users. The
community of developers who contributed to the project grew, and Linux evolved
into a highly stable, secure, and versatile operating system that could be used on
a wide range of computer hardware. By the late 1990s, Linux had gained a
reputation as a high-performance and reliable operating system, and it began to
be adopted by many businesses and organizations for use in servers and other
applications. Today, Linux is widely used in many areas, including servers,
desktops, smartphones, embedded devices, and cloud computing. The
development of Linux continues to be driven by a large and vibrant community of
developers and users, who collaborate and contribute to the project in a variety
of ways. Linux has become one of the most influential open-source projects in
history and continues to play a critical role in shaping the future of computing.

The history of Linux can be traced back to the late 1980s and early 1990s. Linus
Torvalds, a student at the University of Helsinki, began developing a new
operating system as a hobby project. He wanted to create a free and open-source
alternative to the proprietary operating systems that were widely used at the
time. In 1991, Torvalds released the source code for his operating system, which
he named Linux, under the GPL (General Public License). This made it possible for
anyone to use, modify, and redistribute the code as they wished. Over the next
several years, Linux rapidly gained popularity among developers and users. The
community of developers who contributed to the project grew, and Linux evolved
into a highly stable, secure, and versatile operating system that could be used on
a wide range of computer hardware. By the late 1990s, Linux had gained a
reputation as a high-performance and reliable operating system, and it began to

45
be adopted by many businesses and organizations for use in servers and other
applications. Today, Linux is widely used in many areas, including servers,
desktops, smartphones, embedded devices, and cloud computing. The
development of Linux continues to be driven by a large and vibrant community of
developers and users, who collaborate and contribute to the project in a variety
of ways. Linux has become one of the most influential open-source projects in
history and continues to play a critical role in shaping the future of computing.
Features of Linux, Linux has many features that make it an attractive operating
system for a wide range of uses. Some of the most notable features of Linux
include:
• Open Source: Linux is freely available and the source code can be modified
and distributed by anyone. This makes it an attractive choice for developers
and businesses.
• Versatility: Linux can be used on a wide range of hardware, from
smartphones and embedded devices to servers and supercomputers.
• Customizability: Linux is highly customizable, and users can configure the
operating system to suit their specific needs.
• Security: Linux is known for its high level of security, which is achieved
through a combination of strong access controls, secure file permissions,
and a focus on security in software design and development.
• Stable and Reliable: Linux is widely regarded as a highly stable and reliable
operating system, and it is used by many businesses and organizations for
critical applications.
• Large Software Library: Linux has a large and growing library of software
applications, many of which are available for free.
• User-Friendly: Linux has a growing reputation as a user-friendly operating
system, and there are many graphical user interfaces and software tools
available to make it easy to use.
• Support: Linux has a large and active user community, and there is a wealth
of support available, including online forums, documentation, and paid
support options. These are just a few of the features of Linux, and the
operating system continues to evolve and improve over time, driven by the
contributions of a large and active community of developers and users.

46
Drawbacks of Linux: Linux is widely regarded as a powerful and versatile
operating system, but like any software, it is not perfect and has some drawbacks,
including:
• Steep Learning Curve: For new users, Linux can be difficult to learn,
particularly if they are used to more user-friendly operating systems like
Windows.
• Fragmentation: There are many different distributions (or "distros") of
Linux, and this can make it difficult to find support and software that works
on a particular version of the operating system.
• Compatibility Issues: Linux is not as widely supported as Windows, and
some hardware and software may not work properly on Linux systems.
• Command Line Interface: While Linux has many user-friendly graphical
interfaces, it is also heavily reliant on the command line interface, which
can be intimidating for some users.
• Limited Gaming Support: Linux has limited support for gaming, and many
popular games are not available for the operating system.
• Cost of Commercial Support: While Linux itself is free, commercial support
can be expensive, and businesses may need to pay for support in order to
get help with certain tasks or to receive software updates.
• Software Availability: While Linux has a large library of software, many
commercial applications are not available for Linux, which can limit the
operating system's appeal to some users. These drawbacks should not be
seen as insurmountable, however, and for many users, the benefits of Linux
far outweigh its limitations. With continued growth and development, it is
likely that the operating system will continue to improve and overcome
some of these challenges over time.
Components of Linux The components of Linux include:
• Kernel: The core component of the operating system, responsible for
managing hardware and system resources and providing an interface for
other components.

47
• Shell: A command-line interface that allows users to interact with the
operating system and execute commands.
• File System: A hierarchical file structure that organizes and stores data on
the system.
• Utilities: Small programs that perform specific functions, such as managing
files, managing users, or handling text manipulation.
• Libraries: Collections of pre-written code that can be used by other
programs, including utilities and applications.
• Desktop Environment: A graphical user interface that provides a more
user-friendly way to interact with the system, including a menu-based
system for launching applications, a taskbar for managing open windows,
and a file manager for organizing files.
• Applications: Programs that perform specific tasks, such as word
processing, web browsing, email, or multimedia playback.
• Package Management System: A software system that automates the
installation, removal, and upgrade of applications and libraries.
• System Administration Tools: Programs used by system administrators to
manage the system, including tools for managing users, disk usage, and
network connections. These components work together to provide a
complete operating system, capable of running a wide range of applications
and supporting a variety of use cases, from desktop computing to servers
and supercomputers.
Memory Management Subsystems: The Memory Management Subsystem in an
operating system is responsible for managing the physical and virtual memory
available on a computer. It provides mechanisms for allocating and deallocating
memory to applications and the operating system itself. The following are some
of the key components of a memory management subsystem:
• Virtual Memory: A technique for extending the amount of usable memory
by temporarily transferring data from RAM to disk.
• Paging: A method of dividing physical memory into fixed-sized units (pages)
and allocating them to processes as needed.

48
• Segmentation: A method of dividing virtual memory into variable-sized
segments, with each segment corresponding to a different aspect of a
process, such as its code, data, or heap.
• Memory Allocators: Algorithms and data structures used to manage the
allocation and deallocation of memory, such as the buddy allocator or the
slab allocator.
• Caching: A mechanism for temporarily storing frequently accessed data in
fast, readily accessible memory, such as the disk cache or the CPU cache.
• Swapping: A technique for temporarily transferring data from RAM to disk
when there is not enough physical memory to hold all the active processes.
• Memory Pools: Collections of pre-allocated memory that can be used by
processes as needed, reducing the overhead of allocating and deallocating
memory. These components work together to ensure that applications
have access to the memory they need, while also managing the limited
physical memory resources of the system in an efficient and effective
manner.

Linux Process and Thread Management: The Linux operating system uses a
process and thread management system to handle multiple tasks concurrently.
The following are some key components of the Linux process and thread
management system:
• Processes: A process is a self-contained execution environment that
consists of a program, its data, and the system resources it uses. Each
process has its own memory space, file descriptors, and system contexts.
• Threads: A thread is a lightweight execution unit within a process that
shares the same memory space and system contexts. Threads allow
multiple tasks to run concurrently within a single process, improving the
overall performance of the system.
• Scheduler: The Linux scheduler is responsible for deciding which process or
thread should run next and for how long. The scheduler uses various
algorithms to determine the priority of processes and threads and to
manage the allocation of CPU time.

49
• Inter-process Communication (IPC): Linux provides several mechanisms for
processes to communicate and coordinate with each other, including pipes,
sockets, message queues, and semaphores.
• Signals: Signals are a way for processes to send notifications to each other,
such as to indicate that a process has completed a task or that a user has
requested that a process be terminated.
• Context Switching: The process of switching from one process or thread to
another is known as a context switch. Linux implements context switching
in a highly optimized manner, allowing multiple processes and threads to
run efficiently on the same CPU. These components work together to
provide a robust and flexible process and thread management system that
supports multi-tasking and concurrent execution of multiple applications
and services on the Linux platform.
File Management System Device Drivers: File Management System: The file
management system in Linux is responsible for organizing and managing the files
and directories stored on the system's hard disk or other storage media. Linux
uses a hierarchical file system structure, in which files and directories are
organized in a tree-like fashion, starting from the root directory.
Some key components of the Linux file management system include:
• Directories: A directory is a collection of files and other directories that are
organized in a specific structure. Directories provide a way to categorize
and organize files, making it easier to manage and access them.
• File System: The file system in Linux is responsible for storing and retrieving
files and directories on the disk. Linux supports several file system types,
including the commonly used ext2, ext3, and ext4 file systems.
• Mount Points: The process of attaching a file system to a specific location
in the file hierarchy is known as mounting. Mount points provide a way to
access files and directories stored on different file systems as if they were
part of the same hierarchy.
• Inodes: An inode is a data structure that contains information about a file,
such as its size, permissions, ownership, and timestamps. Each file on the
Linux file system is associated with a unique inode number.

50
File Descriptors: A file descriptor is a unique integer that represents an open file
on the system. File descriptors are used by the file management system to access
files and perform various operations, such as reading, writing, and closing files.
Device Drivers: Device drivers are software components that allow the operating
system to communicate with and control various hardware devices, such as disks,
printers, and network interfaces. In Linux, device drivers are typically
implemented as loadable kernel modules that can be loaded and unloaded
dynamically, without requiring a reboot. Device drivers in Linux provide a
standardized interface for accessing and controlling hardware devices, which
simplifies the development of new drivers and enhances the overall stability and
reliability of the system. Some of the key features of Linux device drivers include:
• Loadable Modules: Linux device drivers can be loaded and unloaded
dynamically, without requiring a reboot of the system. This allows
administrators to add and remove support for new hardware devices
without disrupting the operation of the system.
• Plug and Play Support: Linux provides support for plug and play devices,
allowing the operating system to automatically detect and configure new
hardware as it is added to the system.
• Device File System: The /dev file system in Linux provides a way to access
and control devices using standard file operations, such as open, close,
read, and write.
• Device Classes: Linux supports a hierarchical system for organizing device
drivers into different device classes, such as block devices, character
devices, and network devices. Overall, the Linux device driver architecture
provides a flexible and scalable framework for supporting a wide range of
hardware devices, from small embedded systems to large enterprise
servers.

51

You might also like