Aos Unit-1
Aos Unit-1
UNIT - 1
What is OS?
• Traditional Operating System : which ran on stand- alone computers with single
processors.
• Arise of Multiprocessor Systems and Distributed Systems.
• Due to the high demand and popularity of multiprocessor systems, advanced operating
system have gained high importance.
Types
• In operating systems, to improve the performance of more than one CPU can be used
within one computer system called Multiprocessor operating system.
• Multiple CPUs are interconnected so that a job can be divided among them for faster
execution.
• When a job finishes, results from all CPUs are collected and compiled to give the final
output.
• Jobs needed to share main memory and they may also share other system resources
among themselves.
• Multiple CPUs can also be used to run multiple jobs simultaneously.
For Example: UNIX Operating system is one of the most widely used multiprocessing systems.
The basic organization of a typical multiprocessing system is shown in the given figure.
828.claims he was more considerate than Twitter's Elon Musk over Meta layoffs
To employ a multiprocessing operating system effectively, the computer system must have
the following things:
• In a Symmetrical multiprocessing system, each processor executes the same copy of the
operating system, takes its own decisions, and cooperates with other processes to smooth
the entire functioning of the system.
• The CPU scheduling policies are very simple.
• Any new job submitted by a user can be assigned to any processor that is least burdened.
It also results in a system in which all processors are equally burdened at any time.
• The symmetric multiprocessing operating system is also known as a "shared every-thing"
system, because the processors share memory and the Input output bus or data path.
• In this system processors do not usually exceed more than 16.
o These systems are fault-tolerant. Failure of a few processors does not bring the entire
system to a halt.
In the above figure, the asymmetric processing system shows that CPU n1 acts as a supervisor
whose function controls other following processors.
In this type of system, each processor is assigned a specific task, and there is a designated master
processor that controls the activities of other processors.
For example, we have a math co-processor that can handle mathematical jobs better than the
main CPU. Similarly, we have an MMX processor that is built to handle multimedia-related jobs.
Similarly, we have a graphics processor to handle the graphics-related job better than the main
processor. When a user submits a new job, the OS has to decide which processor can perform it
better, and then that processor is assigned that newly arrived job. This processor acts as the
master and controls the system. All other processors look for masters for instructions or have
predefined tasks. It is the responsibility of the master to allocate work to other processors.
o In this type of multiprocessing operating system the processors are unequally burdened.
One processor may be having a long job queue, while another one may be sitting idle.
o In this system, if the process handling a specific work fails, the entire system will go
down.
Overview
The operating system provides an environment for the users to execute computer
programs.
Operating systems are already installed on the computers you buy for eg personal
computers have windows, Linux, and macOS, mainframe computers have z/OS, z/VM,
etc, and mobile phones have operating systems such as Android, and iOS.
The architecture of an operating system consists of four major components hardware,
kernel, shell, and application and we shall explore all of them in detail one by one.
Scope
Highlights:
Software running on any operating system can be system software and application
software.
The operating system as we know is an intermediary and its functionalities include file
management, memory management, process management, handling input and output, and
peripheral devices as well.
The operating system handles all of the above tasks for the system as well as application
software.
The architecture of an operating system is basically the design of its software and
hardware components.
Depending upon the tasks or programs we need to run users can use the operating system
most suitable for that program/software.
User- 1 User- 2
System Application
software software
Software
Operating system
Hardware
CPU RAM I/O
Before explaining various architectures of the operating systems, let's explore a few terms first
which are part of the operating system.
1) Application:
The application represents the software that a user is running on an operating system it
can be either system or application software.
eg slack, sublime text editor, etc.
2) Shell:
The shell represents software that provides an interface for the user where it serves to
launch or start some program for which the user gives instructions.
It can be of two types first is a command line and another is a graphical user interface.
for eg: MS-DOS Shell, PowerShell, csh, ksh, etc.
3) Kernel:
Kernel represents the most central and crucial part of the operating system where it is
used for resource management.
i.e. it provides necessary I/O, processor, and memory to the application processes
through inter-process communication mechanisms and system calls.
Let's understand the various types of architectures of the operating system.
Highlights:
1) Monolithic Architecture
In monolithic architecture, each component of the operating system is contained
in the kernel.
i.e. it is working in kernel space, and the components of the operating system
communicate with each other using function calls.
Applications
_______________________________________________________User Space________
Kernel space
System call interfaces
kernel
MM IPC PS
FS I/O Net
Advantages:
1. The main advantage of having a monolithic architecture of the operating system is that it
provides CPU scheduling, memory management, memory management, etc through
system calls.
2. In a single address space, the entire large process is running.
3. It is a single static binary file.
Disadvantages:
1. The main disadvantage is that all components are interdependent and when one of them
fails the entire system fails.
2. In case the user has to add a new service or functionality the entire operating system
needs to be changed.
2) Layered architecture
1. Each layer can communicate with all of its lower layers but not with its upper layer i.e.
any ith layer can communicate with all layers from 0 to i-1 but not with the i+1th layer.
2. Each layer is designed in such a way that it will only need the functionalities which are
present in itself or the layers below it.
System services
File systems
Process scheduling
Hardware
1) Hardware:
This layer is the lowest layer in the layered operating system architecture.
This layer is responsible for the coordination with peripheral devices such
as keyboards, mice, scanners etc.
2) CPU scheduling:
This layer is responsible for process scheduling, multiple queues are used for scheduling.
Process entering the system are kept in the job queue while those which are ready to be
executed are put into the ready queue.
It manages the processes which are to be kept in the CPU and those which are to be kept
out of the CPU.
3) Memory Management:
This layer handles the aspect of memory management i.e. moving the processes from the
secondary to primary memory for execution and vice-versa.
There are memories like RAM, and ROM.
RAM is the memory where our processes run they are moved to the RAM for execution
and when they exit they are removed from RAM.
4) Process Management:
This layer is responsible for managing the various processes i.e. assigning the CPU to
those processes on a priority basis for their execution.
Process management uses many scheduling algorithms for prioritizing the processes for
execution such as the Round-Robin algorithm, FCFS(First Come First
Serve), SJF(Shortest Job First), etc.
5) I/O Buffer:
Buffering is the temporary storage of data and I/O Buffer means that the data input is first
buffered before storing it in the secondary memory.
All I/O devices have buffers attached to them for the temporary storage of the input data
because it cannot be stored directly in the secondary storage as the speed of
the I/O devices is slow as compared to the processor.
6) User Programs:
This is the application layer of the layered architecture of the operating system, it deals
with all the application programs running.
Eg: games, browsers, words, etc. It is the highest layer of layered architecture.
Advantages:
1) Layered architecture of the operating system provides modularity because each layer is
programmed to perform its own tasks only.
2) Since the layered architecture has independent components changing or updating one of
them will not affect the other component or the entire operating system will not stop
working, hence it is easy to debug and update.
3) The user can access the services of the hardware layer but cannot access the hardware
layer itself because it is the innermost layer.
4) Each layer has its own functionalities and it is concerned with itself only and other layers
are abstracted from it.
Disadvantages:
1) Layered architecture is complex in implementation because one layer may use the
services of the other layer and therefore, the layer using the services of another layer must
be put below the other one.
2) In a layered architecture, if one layer wants to communicate with another it has to send a
request which goes through all layers in between which increases response time causing
inefficiency in the system.
3) Microkernel Architecture
In this architecture, the components like process management, networking, file system
interaction, and device management are executed outside the kernel while memory
management and synchronization are executed inside the kernel.
The processes inside the kernel have relatively high priority, the components
possess high modularity hence even if one or more components fail the operating system
keeps on working.
Applications
IPC
Advantages:
1. Microkernel operating systems are modular and hence, disturbing one of the components
will not affect the other component.
2. The architecture is compact and isolated and hence relatively efficient.
3. New features can be added without recompilation.
Disadvantages:
4) Hybrid Architecture
Hybrid architecture as the name suggests consists of a hybrid of all the architectures
explained so far and hence it has properties of all of those architectures which makes it
highly useful in present-day operating systems.
The hybrid-architecture consists of three layers
1) Hardware abstraction layer: It is the interface between the kernel and hardware and is
present at the lowest level.
2) Microkernel Layer: This is the old microkernel that we know and it consists of CPU
scheduling, memory management, and inter-process communication.
3) Application Layer: It acts as an interface between the user and the microkernel. It contains
the functionalities like a file server, error detection, I/O device management, etc.
Advantages:
Disadvantage:
1. Hybrid architecture of the operating system keeps certain services in the kernel space
while moving less critical services to the user space.
Conclusion
We conclude that the operating system has various architectures with which we can
describe the functionality of various components.
The components of the operating system are process management, memory
management, I/O management, Error Detection, and controlling peripheral devices.
These architectures include monolithic, layered, microkernel, and hybrid architectures
classified on the basis of the structure of components.
Hybrid architecture is the most efficient and useful architecture as it implements the
functionalities of all other architectures.
Hybrid architecture is better in terms of security as well.
1) How the Hybrid Architecture of Operating Systems is Better Than Other Architectures?
The hybrid architecture of operating systems as we know is a hybrid of other architectures like
monolithic, layered, and microkernel architectures of operating systems so it has the
functionalities of all of them. Since, we can see that hybrid architecture contains all the
functionalities of monolithic, layered, and microkernel architecture, therefore it is better than all
of them.
2) What are the Key Differences Between Monolithic and Layered Architecture of
Operating Systems?
The key differences between the monolithic and layered architecture of the operating system are:
1. In the monolithic operating system the entire operating system functionalities operate in
the kernel space while in layered architecture there are several layers where each layer
has a specific set of functionalities.
2. In the monolithic operating system there are mainly three layers while in a layered the
number of layers is multiple.
The kernel and shell are the parts of the operating system that perform essential
operations.
When a user gives commands for performing any operation, the request goes to the shell
part, which is also known as an interpreter.
The shell part then translates the human program into machine code and then transfers the
request to the kernel part.
When the kernel receives the request from the shell, it processes the request and displays
the result on the screen.
The kernel is also known as the heart of the operating system as every operation is
performed by it.
Shell
The shell is a part of the software which is placed between the user and the kernel, and it
provides services of the kernel.
The shell thus acts as an interpreter to convert the commands from the user to the
machine code.
Shells present in different types of operating systems are of two types: command-line
shells and graphical shells.
The command-line shells provide a command-line interface while graphical line shells
provide a graphical user interface.
Though both shells perform operations, the graphical user interface shells perform slower
than the command line interface shells.
Types of shells
Korn shell
Bourne shell
C shell
POSIX shell
Kernel
It is responsible for running programs and providing secure access to the machine’s
hardware.
The kernel is used for scheduling, i.e., it maintains a time table for all processes.
Types of kernels:
Monolithic kernel
Microkernels
Exokernels
Hybrid kernels
Memory Management
Process Management
There are two types of process methods: single process and multitasking method.
The single process method deals with a single application running at a time. The
multitasking method allows multiple processes at a time.
Storage Management
Instructions and data are placed in the primary storage or cache memory, which is
referenced by the running program.
However, the data is lost when the power supply cut off. The secondary memory is a
permanent storage device.
The operating system allocates a storage place when new files are created and the request
for memory access is scheduled.
In computer architecture, the combination of CPU and main memory is the brain of the
computer, and it is managed by the input and output resources.
Humans interact with the machines by providing information through I/O devices.
The management of all these devices affects the throughput of a system; therefore, the
input and output management of the system is a primary responsibility of the operating
system
Scheduling
The operating system maintains a constant amount of work for the processor and thus
balances the workload. As a result, each process is completed within a stipulated time
frame.
Hence, scheduling is very important in real-time systems. The schedulers are mainly of three
types:
Simple Structure
It is the simplest Operating System Structure and is not well defined; It can only be used
for small and limited systems.
In this structure, the interfaces and levels of functionality are well separated; hence
programs can access I/O routines which can cause unauthorized access to I/O routines.
The MS-DOS operating System is made up of various layers, each with its own set of
functions.
These layers are:
o Application Program
o System Program
o MS-DOS device drivers
o ROM BIOS device drivers
Layering has an advantage in the MS-DOS operating system since all the levels can be
defined separately and can interact with each other when needed.
It is easier to design, maintain, and update the system if it is made in layers. So that's why
limited systems with less complexity can be constructed easily using Simple Structure.
If one user program fails, the entire operating system gets crashed.
The abstraction level in MS-DOS systems is low, so programs and I/O routines are
visible to the end-user, so the user can have unauthorized access.
Application Program
System Programs
Device Derivers
Monolithic Structure
The Monolithic operating System in which the kernel acts as a manager by managing all
things like file management, memory management, device management, and operational
processes of the Operating System.
The kernel is the heart of a computer operating system (OS).
Kernel delivers basic services to all other elements of the System.
It serves as the primary interface between the Operating System and the hardware.
In monolithic systems, kernels can directly access all the resources of the operating
System like physical hardware, exp Keyboard, Mouse etc.
The monolithic kernel is another name for the monolithic operating system.
Batch processing and time-sharing maximize the usability of a processor by
multiprogramming.
The monolithic kernel functions as a virtual machine by working on top of the Operating
System and controlling all hardware components.
This is an outdated operating system that was used in banks to
accomplish minor activities such as batch processing and time-sharing, which enables
many people at various terminals to access the Operating System.
Unprivileged
Applications Applications Applications
mode
Memory Process
management management Drivers
monolithic kernel
Advantages of Monolithic structure:
It is simple to design and implement because all operations are managed by kernel only,
and layering is not needed.
As services such as memory management, file management, process scheduling, etc., are
implemented in the same address space, the execution of the monolithic kernel is
relatively fast as compared to normal systems. Using the same address saves time for
address allocation for new processes and makes it faster.
If any service in the monolithic kernel fails, the entire System fails because, in address
space, the services are connected to each other and affect each other.
It is not flexible, and to introduce a new service
Layered Approach
Each layer has its functionalities, so work tasks are isolated, and abstraction is present up
to some level.
Debugging is easier as lower layers are debugged, and then upper layers are checked.
Micro-kernel
Application layer
The operating System enables the end-user to interact with the computer hardware.
System software is installed and utilized on top of the operating system.
We can define operating system structure as to how different components of the
operating system are interconnected.
There are many structures of the operating system:
o Simple Structure
o Monolithic Approach
o Layered Approach
o Micro-kernels
All these approaches or structures evolved from time to time, making the OS more and
more improved than before.
o Ideally, handle all I/O devices in the same way; Both in the OS and in user applications
o Problem:
Especially, different access methods (random access versus stream based) as well as
vastly different data rates.
Robustness
In computer science, robustness is the ability of a computer system to cope with errors
during execution and cope with erroneous input.
Robustness can encompass many areas of computer science, such as robust
programming, robust machine learning, and Robust Security Network.
Formal techniques, such as fuzz testing, are essential to showing robustness since this
type of testing involves invalid or unexpected inputs.
Alternatively, fault injection can be used to test robustness.
Various commercial products perform robustness testing of software analysis.
A distributed system may suffer from various types of hardware failure.
The failure of a link, the failure of a site, and the loss of a message are the most common
types. To ensure that the system is robust, we must detect any of these failures,
reconfigure the system so that computation can continue, and recover when a site or a
link is repaired.
Portability
Portability is the ability of an application to run properly in a different platform to the one
it was designed for, with little or no modification.
Portability in high-level computer programming is the usability of the same software in
different environments.
When software with the same functionality is produced for several computing platforms,
portability is the key issue for development cost reduction.
Compatibility
Compatibility is the capacity for two systems to work together without having to be
altered to do so.
Compatible software applications use the same data formats. For example, if word
processor applications are compatible, the user should be able to open their document
files in either product.
Compatibility issues come up when users are using the same type of software for a task,
such as word processors, that cannot communicate with each other.
This could be due to a difference in their versions or because they are made by different
companies.
The huge variety of application software available and all the versions of the same
software mean there are bound to be compatibility issues, even when people are using the
same kind of software.
Compatibility issues come up when users are using the same type of software for a task,
such as word processors, that cannot communicate with each other.
Flexibility
Flexible operating systems are taken to be those whose designs have been motivated to
some degree by the desire to allow the system to be tailored, either statically or
dynamically, to the requirements of specific applications or application domains.
Process Synchronization in OS
What is Process Synchronization in OS?
An operating system is a software that manages all applications on a device and basically
helps in the smooth functioning of our computer.
Because of this reason, the operating system has to perform many tasks, and sometimes
simultaneously.
This isn't usually a problem unless these simultaneously occurring processes use a
common resource.
For example, consider a bank that stores the account balance of each customer in the
same database. Now suppose you initially have x rupees in your account. Now, you take
out some amount of money from your bank account, and at the same time, someone tries
to look at the amount of money stored in your account. As you are taking out some
money from your account, after the transaction, the total balance left will be lower than x.
But, the transaction takes time, and hence the person reads x as your account balance
which leads to inconsistent data. If in some way, we could make sure that only one
process occurs at a time, we could ensure consistent data.
Process1 process 1
User 1 Accounts User 2
A
In the above image, if Process1 and Process2 happen at the same time, user 2 will get the
wrong account balance as Y because of Process1 being transacted when the balance is X.
Inconsistency of data can occur when various processes share a common resource in a
system which is why there is a need for process synchronization in the operating system.
read
Process 3
Race Condition
When more than one process is either running the same code or modifying the same
memory or any shared data, there is a risk that the result or value of the shared data may
be incorrect because all processes try to access and modify this shared resource.
Thus, all the processes race to say that my result is correct.
This condition is called the race condition.
Since many processes use the same data, the results of the processes may depend on the
order of their execution.
This is mostly a situation that can arise within the critical section. In the critical section, a race
condition occurs when the end result of multiple thread executions varies depending on the
sequence in which the threads execute.
by treating the critical section as a section that can be accessed by only a single process at
a time. This kind of section is called an atomic section.
Why do we need to have a critical section? What problems occur if we remove it?
A part of code that can only be accessed by a single process at any moment is known as
a critical section.
This means that when a lot of programs want to access and change a single shared data,
only one process will be allowed to change at any given moment.
The other processes have to wait until the data is free to be used.
The wait() function mainly handles the entry to the critical section, while the signal() function
handles the exit from the critical section. If we remove the critical section, we cannot
guarantee the consistency of the end outcome after all the processes finish executing
simultaneously.
We'll look at some solutions to Critical Section Problem but before we move on to that, let us
take a look at what conditions are necessary for a solution to Critical Section Problem.
Requirements of Synchronization
The following three requirements must be met by a solution to the critical section problem:
Mutual exclusion: If a process is running in the critical section, no other process should
be allowed to run in that section at that time.
Progress: If no process is still in the critical section and other processes are waiting
outside the critical section to execute, then any one of the threads must be permitted to
enter the critical section. The decision of which process will enter the critical section will
be taken by only those processes that are not executing in the remaining section.
No starvation: Starvation means a process keeps waiting forever to access the critical
section but never gets a chance. No starvation is also known as Bounded Waiting.
o A process should not wait forever to enter inside the critical section.
o When a process submits a request to access its critical section, there should be a
limit or bound, which is the number of other processes that are allowed to access
the critical section before it.
o After this bound is reached, this process should be allowed to access the critical
section.
Let us now discuss some of the solutions to the Critical Section Problem.
Peterson's solution
In Peterson's solution, we have two shared variables that are used by the processes.
A boolean Flag[]: A boolean array Flag which is initialized to FALSE. This Flag array
represents which process is which process wants to enter into the critical solution.
int Turn: A integer variable Turn indicates the process number which is ready to enter
into the critical section.
do{
//A process Pi wants to enter into the critical section
{ Critical Section };
Flag[i] = False;
// another process can go to Critical Section
Turn = j;
Remainder Section
} while ( True);
Synchronization Hardware
Hardware can occasionally assist in the solving of critical section issues. Some operating
systems provide a lock feature.
When a process enters a critical section, it is given a lock, which the process must release
before the process can exit the critical section.
As a result, additional processes are unable to access a critical section if anyone process
is already using the section. The lock can have either of the two values, 0 or 1.
Mutex Locks
Semaphores
A semaphore is a signaling mechanism, and a process can signal a process that is waiting
on a semaphore.
This differs from a mutex in that the mutex can only be notified by the process that sets
the shared lock.
Semaphores make use of the wait() and signal() functions for synchronization among the
processes.
Binary Semaphores
Binary Semaphores can only have one of two values: 0 or 1. Because of their capacity to ensure
mutual exclusion, they are also known as mutex locks.
Hence, whenever the binary semaphore is set to 0, any process can then enter its critical section
by setting the binary semaphore to 1. When it has completed its critical section, it can reset the
binary semaphore to 0, enabling another process to enter it.
Counting Semaphores
Counting Semaphores can have any value and are not limited to a certain area. They can be used
to restrict access to a resource that has a concurrent access limit.
Initially, the counting semaphores are set to the maximum amount of processes that can access
the resource at a time. Hence, the counting semaphore indicates that a process can access the
resource if it has a value greater than 0. If it is set to 0, no other process can access the resource.
Hence,
When a process wants to use that resource, it first checks to see if the value of the
counting semaphore is more than zero.
If yes, the process can then proceed to access the resource, which involves reducing the
value of the counting semaphore by one.
When the process completes its critical section code, it can increase the value of the
counting semaphore, making way for some other process to access it.
The snippet code for semaphore would seem something like this:
WAIT ( SE );
while ( SE <= 0 );
SE = SE - 1;
SIGNAL ( SE );
SE = SE + 1;
:::
Conclusion
Synchronization is the effort of executing processes such that no two processes have
access to the same shared data.
Four elements of program/data are:
o Entry section
o Critical section
o Exit section
o Reminder section
The critical section is a portion of code that a single process can access at a specified
moment in time.
Three essential rules that any critical section solution must follow are as follows:
o Mutual Exclusion
o Progress
o No Starvation(Bounded waiting)
Solutions to critical section problem are:
o Peterson's solution
o Synchronization hardware
o Mutex Locks
o Semaphore
Definition
The process scheduling is the activity of the process manager that handles the removal of
the running process from the CPU and the selection of another process on the basis of a
particular strategy.
Process scheduling is an essential part of a Multiprogramming operating systems.
Such operating systems allow more than one process to be loaded into the executable
memory at a time and the loaded process shares the CPU using time multiplexing.
Categories of Scheduling
1. Non-preemptive: Here the resource can’t be taken from a process until the process
completes execution. The switching of resources occurs when the running process
terminates and moves to a waiting state.
2. Preemptive: Here the OS allocates the resources to a process for a fixed amount of time.
During resource allocation, the process switches from running state to ready state or from
waiting state to ready state. This switching occurs as the CPU may give priority to other
processes and replace the process with higher priority with the running process.
The OS maintains all Process Control Blocks (PCBs) in Process Scheduling Queues.
The OS maintains a separate queue for each of the process states and PCBs of all
processes in the same execution state are placed in the same queue.
When the state of a process is changed, its PCB is unlinked from its current queue and
moved to its new state queue.
The Operating System maintains the following important process scheduling queues −
Job queue − This queue keeps all the processes in the system.
Ready queue − This queue keeps a set of all processes residing in main memory, ready
and waiting to execute. A new process is always put in this queue.
Device queues − The processes which are blocked due to unavailability of an I/O device
constitute this queue.
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority,
etc.).
The OS scheduler determines how to move processes between the ready and run queues
which can only have one entry per processor core on the system; in the above diagram, it
has been merged with the CPU.
Two-state process model refers to running and non-running states which are described below −
S.N. State & Description
1
Running
When a new process is created, it enters into the system as in the
running state.
2
Not Running
Processes that are not running are kept in queue, waiting for their
turn to execute. Each entry in the queue is a pointer to a particular
process. Queue is implemented by using linked list. Use of
dispatcher is as follows. When a process is interrupted, that
process is transferred in the waiting queue. If the process has
completed or aborted, the process is discarded. In either case, the
dispatcher then selects a process from the queue to execute.
Schedulers
Schedulers are special system software which handle process scheduling in various ways. Their
main task is to select the jobs to be submitted into the system and to decide which process to run.
Schedulers are of three types −
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
It is also called a job scheduler. A long-term scheduler determines which programs are
admitted to the system for processing.
It selects processes from the queue and loads them into memory for execution. Process
loads into the memory for CPU scheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as
I/O bound and processor bound.
It also controls the degree of multiprogramming.
If the degree of multiprogramming is stable, then the average rate of process creation
must be equal to the average departure rate of processes leaving the system.
On some systems, the long-term scheduler may not be available or minimal.
Time-sharing operating systems have no long term scheduler.
When a process changes the state from new to ready, then there is use of long-term
scheduler.
It is also called as CPU scheduler. Its main objective is to increase system performance
in accordance with the chosen set of criteria.
It is the change of ready state to running state of the process.
CPU scheduler selects a process among the processes that are ready to execute and
allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next. Short-term schedulers are faster than long-term schedulers.
Context Switching
A context switching is the mechanism to store and restore the state or context of a CPU in
Process Control block so that a process execution can be resumed from the same point at
a later time.
Using this technique, a context switcher enables multiple processes to share a single
CPU. Context switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute another, the
state from the current running process is stored into the process control block.
After this, the state for the process to run next is loaded from its own PCB and used to set
the PC, registers, etc. At that point, the second process can start executing.
Context switches are computationally intensive since register and memory state must be
saved and restored.
To avoid the amount of context switching time, some hardware systems employ two or
more sets of processor registers.
When the process is switched, the following information is stored for later use.
Program Counter
Scheduling information
Base and limit register value
Currently used register
Changed State
I/O State information
Accounting information
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
P1 1 3 5
P2 2 8 14
P3 3 6 8
P0 0-0=0
P1 5-1=4
P2 14 - 2 = 12
P3 8-3=5
Priority scheduling is a non-preemptive algorithm and one of the most common scheduling
algorithms in batch systems.
Each process is assigned a priority. Process with highest priority is to be executed first and
so on.
Processes with same priority are executed on first come first served basis.
Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
Given: Table of processes, and their Arrival time, Execution time, and priority. Here we are
considering 1 is the lowest priority.
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5
P0 0-0=0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5-3=2
Shortest remaining time (SRT) is the preemptive version of the SJN algorithm.
The processor is allocated to the job closest to completion but it can be preempted by a
newer ready job with shorter time to completion.
Impossible to implement in interactive systems where required CPU time is not known.
It is often used in batch environments where short jobs need to give preference.
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
Multiple-level queues are not an independent scheduling algorithm. They make use of other
existing algorithms to group and schedule jobs with common characteristics.
Multiple queues are maintained for processes with common characteristics.
Each queue can have its own scheduling algorithms.
Priorities are assigned to each queue.
For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in another
queue. The Process Scheduler then alternately selects jobs from each queue and assigns them to
the CPU based on the algorithm assigned to the queue.
Memory Management in Operating System (OS)
Memory is the important part of the computer that is used to store the data.
Its management is critical to the computer system because the amount of main memory
available in a computer system is very limited.
At any time, many processes are competing for it. Moreover, to increase performance,
several processes are executed simultaneously.
For this, we must keep several processes in the main memory, so it is even more
important to manage them effectively.
Role of Memory management
o Memory manager is used to keep track of the status of memory locations, whether it is
free or allocated. It addresses primary memory by providing abstractions so that software
perceives a large memory is allocated to it.
o Memory manager permits computers with a small amount of main memory to execute
programs larger than the size or amount of available memory. It does this by moving
information back and forth between primary memory and secondary memory by using
the concept of swapping.
o The memory manager is responsible for protecting the memory allocated to each process
from being corrupted by another process. If this is not ensured, then the system may
exhibit unpredictable behavior.
o Memory managers should enable sharing of memory space between processes. Thus, two
programs can reside at the same memory location although at different times.
The memory management techniques can be classified into following main categories:
o Simple to implement.
o Easy to manage and design.
o In a Single contiguous memory management scheme, once a process is loaded, it is given
full processor's time, and no other processor will interrupt it.
o Wastage of memory space due to unused memory as the process is unlikely to use all the
available memory space.
o The CPU remains idle, waiting for the disk to load the binary image into the main
memory.
o It can not be executed if the program is too large to fit the entire available main memory
space.
o It does not support multiprogramming, i.e., it cannot handle multiple programs
simultaneously.
Multiple Partitioning:
o Fixed Partitioning
o Dynamic Partitioning
Fixed Partitioning
The main memory is divided into several fixed-sized partitions in a fixed partition
memory management scheme or static partitioning.
These partitions can be of the same size or different sizes. Each partition can hold a
single process.
The number of partitions determines the degree of multiprogramming, i.e., the maximum
number of processes in memory.
These partitions are made at the time of system generation and remain fixed after that.
o Simple to implement.
o Easy to manage and design.
The dynamic partitioning was designed to overcome the problems of a fixed partitioning
scheme.
In a dynamic partitioning scheme, each process occupies only as much memory as they
require when loaded for processing.
Requested processes are allocated memory until the entire physical memory is exhausted
or the remaining space is insufficient to hold the requesting process.
In this scheme the partitions used are of variable size, and the number of partitions is not
defined at the system generation time.
o Simple to implement.
o Easy to manage and design.
What is paging?
Advantages of paging:
What is Segmentation?