Operating System
BATCH OPERATING SYSTEM
• In the 1970s, Batch processing was very popular. In this technique, similar types of jobs were
batched together and executed in time. People were used to having a single computer which was
called a mainframe.
• In Batch operating system, access is given to more than one person; they submit their respective
jobs to the system for the execution.
• The system put all of the jobs in a queue on the basis of first come first serve and then executes
the jobs one by one. The users collect their respective output when all the jobs get executed
Disadvantages of Batch
1. Starvation
There are five jobs J1, J2, J3, J4, and J5, present in the batch. If the execution time of J1 is very high, then the
other four jobs will never be executed, or they will have to wait for a very long time. Hence the other
processes get starved.
[Link] Interactive
. Batch Processing is not suitable for jobs that are dependent on the user's input.
. If a job requires the input of two numbers from the console, then it will never get it in the batch
processing scenario since the user is not present at the time of execution.
MULTIPROGRAMMING OPERATING SYSTEM
Multiprogramming is an extension to batch processing where the CPU is always kept busy. Each process
needs two types of system time: CPU time and I/O time.
Advantages of Multiprogramming OS
• Throughput of the system increased as the CPU always had one program to execute.
• Response time can also be reduced
Disadvantages of Multiprogramming OS
• Multiprogramming systems provide an environment in which various systems resources
are used efficiently, but they do not provide any user interaction with the computer system.
MULTIPROCESSING OPERATING SYSTEMS
• In Multiprocessing, Parallel computing is achieved.
• There are more than one processors present in the system which can execute more than
one process at the same time. This will increase the throughput of the system.
MULTIPROCESSING OPERATING SYSTEMS
Advantages of Multiprocessing OS
• Increased reliability Due to the multiprocessing system, processing tasks can be distributed among several
processors This increases reliability as if one processor fails, the task can be given to another processor for
completion
• Increased throughput as number of processors increase more work can be done in less time
Disadvantages of Multiprocessing OS
• Multiprocessing operating system is more complex and sophisticated as it takes care of
multiple CPUs simultaneously.
NETWORK OPERATING SYSTEMS
• An Operating system, which includes software and associated protocols to communicate with other
computers via a network conveniently and cost effectively, is called Network Operating System.
Advantages of Network OS
• In this type of operating system, network traffic reduces due to the division between clients and the server
• This type of system is less expensive to set up and maintain
Disadvantages of Network OS
• In this type of operating system, the failure of any node in a system affects the whole system.
• Security and performance are important issues. So trained network administrators are required for
network administration.
REAL TIME OPERATING SYSTEM
• In Real Time Systems, each job carries a certain deadline within which the job is supposed to be completed,
otherwise, the huge loss will be there, or even if the result is produced, it will be completely useless.
Advantages of Real time OS
• Easy to layout, develop and execute real time applications under the real time operating System
• In a Real time operating system, the maximum utilization of devices and systems
Disadvantages of Real time OS
• Real time operating systems are very costly to develop.
• Real time operating systems are very complex and can consume critical CPU cycles.
TIME SHARING OPERATING SYSTEM
• In the Time Sharing operating system, computer resources are allocated in a time
Advantages of Time Sharing OS
The time-sharing operating system provides effective utilization and sharing of resources.
This system reduces CPU idle and response time.
Disadvantages of Time Sharing OS
Data transmission rates are very high in comparison to other methods.
Security and integrity of user programs loaded in memory and data need to be maintained as many users
access the system at the same time.
dependent fashion to several programs simultaneously.
DISTRIBUTED OPERATING SYSTEM
• The Distributed Operating system is not installed on a single machine, it is divided into parts, and these
parts are loaded on different machines.
Advantages of Distributed OS
• The distributed operating system provides sharing of resources
• This type of system is fault tolerant
Disadvantages of Distributed OS
• Protocol overhead can dominate computation cost.
PROCESS MANAGEMENT
• A Program does nothing unless its instructions are executed by a CPU A program in execution is called a
process.
• There may exist more than one process in the system which may require the same resource at the same
time Therefore, the operating system has to manage all the processes and the resources in a convenient and
efficient way.
Attributes stored in the PCB
1. Process ID: When a process is created, a unique id is assigned to the process which is used for unique
identification of the process in the system
2. Program counter: A program counter stores the address of the last instruction of the process on
which the process was suspended The CPU uses this address when the execution of this process is
resumed.
3. Process State: The Process, from its creation to the completion, goes through various states which
are new, ready, running and waiting.
4. Priority: Every process has its own priority The process with the highest priority among the processes
gets the CPU first
5. General Purpose Registers Every process has its own set of registers which are used to hold the data
which is generated during the execution of the process.
6. List of open files During the execution, every process uses some files which need to be present in the
main memory OS also maintains a list of open files in the PCB.
7. List of open devices OS also maintain the list of all open devices which are used during the execution
of the process.
PROCESS STATE DIAGRAM
As a process executes, it changes state
• new: The process is being created
• ready: The process is waiting (in main memory) to be assigned to a processor
• running: Instructions are being executed
• waiting: The process is waiting for some event (I/O operations) to occur
• terminated: The process has finished execution
SYSTEM CALLS
• A user program requests service from the operating system using system calls
• It is the only method to access the kernel system
• All programs or processes that require resources for execution must use system calls
• System call is one of the exceptions, there are other exceptions in the system like page fault, divide
by zero and Floating point error.
Why do you need system calls in Operating System?
• It is required when a file system wants to create or delete a file.
• If you want to access hardware devices, including a printer, scanner, you need a system call.
• During creation and management of new processes.
INTERRUPTS
• An interrupt is a signal to the processor emitted by hardware or software indicating an event that
needs immediate attention Whenever an interrupt occurs, the controller completes the execution of
the current instruction and starts the execution of an Interrupt Service Routine (ISR) or Interrupt
Handler.
• An ISR is a software process invoked by an interrupt request from a hardware device It handles the
request and sends it to the CPU, interrupting the active process When the ISR is complete, the process
is resumed
• When a device raises an interrupt at the process, the processor first completes the instruction it is
currently executing Then it switches from user mode to the kernel mode It pushes the address of the
last instruction from PC to stack (temporary location) Then it loads the Program Counter ( with the
address of the first instruction of the ISR stored in interrupt vector table Therefore, after handling the
interrupt, the processor switches to user mode and continue with the execution of process
TYPES OF INTERRUPTS
• Hardware Interrupts
A hardware interrupt is an electronic alerting signal sent to the processor from an external device,
like a disk controller or an external peripheral For example, pressing a keyboard key or moving a
mouse triggers hardware interrupts that cause the processor to read the keystroke or mouse position
• Software Interrupts
A software interrupt is caused either by an exceptional condition or a special instruction in the
instruction set which causes an interrupt when it is executed by the processor For example, if the
processor's arithmetic logic unit runs a command to divide a number by zero, to cause a divide by
zero exception, thus causing the computer to abandon the calculation or display an error message
These interrupts are typically called traps or exceptions.
Definition
A thread is the smallest unit of processing that can be performed in an OS
Example
In a browser, many tabs can be viewed as threads MS Word uses many threads formattingtext from one
thread, processing input from another thread, etc
Need of Thread
• It takes far less time to create a new thread in an existing process than to create a new process
• Threads can share the common data, they do not need to use inter p rocess communication
• Context switching is faster when working with threads
• It takes less time to terminate a thread than a process
• We can attain concurrency with threads
Why thread is called lightweight process Each thread contains its own register and stack However,
thread share code, data and files, i.e. thread within a process share address space Threads provide a way
to improve application performance through parallelism.
TWO TYPES OF THREADS
1. User Level Threads
The OS does not recognize the user level thread. User threads can be easily implemented by the
user. Invoking a function result in local function call in user space.
2. Kernel Level Threads
The kernel level thread are managed by the OS. Invoking a function result in systems call in kernel.
USER LEVEL THREAD
Advantages of User Level Thread
• Thread switching does not require Kernel mode privileges
• Fast to create and manage
• Simple management Creating, switching and synchronizing threads done in user space without kernel
intervention
• Fast and efficient switching threads not much more expensive than a function call
Disadvantages of User Level Thread
OS may make poor decisions like:
• scheduling a process with idle threads
• blocking a process due to a blocking thread even though the process has other threads that can run.
Advantages of Kernel Level Threads
• The kernel has full knowledge of all threads.
• Scheduler may decide to give more CPU time to a process having many threads.
• Good for applications that frequently block. If one thread in a process is blocked, the Kernel can
schedule another thread of the same process.
Disadvantages of Kernel Level Threads
• Kernel manages and schedules all threads.
• Significant overhead and increase in kernel complexity.
• Kernel threads are generally slower to create and manage than the user threads.
MULTITHREADING IN OS
• Multithreading allows the application to divide its task into individual threads. In multi threads, the
same process or task can be done by the number of threads.
• With the use of multithreading, multitasking can be achieved.
• The main drawback of single threading systems is that only one task can be performed at a time.
3 TYPES OF MULTITHREADING MODELS:-
1. Many to one multithreading model: The many to one model maps many user levels threads to one
kernel thread. This type of relationship facilitates an effective context switching environment, easily
implemented even on the simple kernel with no thread support
2. One to one multithreading model: The one-to-one model maps a single user level thread to a single
kernel level thread. This type of relationship facilitates the running of multiple threads in parallel.
3. Many to Many multithreading models: In this type of model, there are several user level threads and
several kernel level threads. The number of kernel threads created depends upon a particular
application. The developer can create as many threads as possible at both levels but may not be the
same.
CPU scheduling:
1. Non preemptive Scheduling: Here when a process is allocated CPU, it keeps the processor with it till
it release the processor voluntarily either by reaching to terminating state or waiting state.
2. Preemptive Scheduling: In preemptive scheduling, the CPU can be taken back from the process at
any time during the execution of the process.
MEMORY MANAGEMENT
• Memory is the important part of the computer used to store the program and 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.
NEED FOR MEMORY MANAGEMENT IN OS
• Place programs in memory in such a way that memory is utilized at its fullest extent
• Must enforce memory protection between processes That is, protect different processes from each
other so that they do not interfere with each other's operations
• Allocate space to different application routines
• This technique allows you to check how much memory needs to be allocated to processes that decide
which processor should get memory at what time
• Keep track of each memory location whether it is free or allocated.
Two key role of OS in memory management
• Address translation from logical to physical address Address generated by CPU is for secondary
memory and it is called logical address That address needs to be converted to physical address of
main memory
• Space allocation Deciding which part of process and data to move into and out of memory Allocating
and deallocating memory space as needed
• Keeping track of which parts of memory are currently being used and who is using them.
MEMORY ALLOCATION
Contiguous memory allocation
• Whole program must be loaded in main memory
• Program must be stored in main memory in contiguous fashion
Non-contiguous memory allocation
• A Program is break into parts and these parts are stored in main memory at non-contiguous locations
• It is not required that all parts of a program are loaded in main memory at the same
time Partial loading is allowed.
Single contiguous allocation
• Single allocation is the simplest memory management technique All the computer's memory, usually
with the exception of a small portion reserved for the operating system, is available to the single
application
• Used in the earliest generation of computer systems, e g MS DOS 1981
• An embedded system running a single application might also use this technique
• Here, the main memory is divided into two contiguous areas or partitions, the OS reside permanently
in one partition, generally at the lower memory, and the user process is loaded into the other
partition.
SINGLE CONTIGUOUS ALLOCATION: ADVANTAGES
• Simple to implement.
• Easy to manage and design.
• Once a process is loaded, it is given full processor's time, and no other process will interrupt it.
Single contiguous allocation : Disadvantages
• Wastage of memory space due to unused memory as the process is unlikely to use all the available
memory space
• The CPU remains idle, waiting for the disk to load the binary image into the main memory
• It can not be executed if the program is too large to fit the available main memory space
• It does not support multiprogramming.
MULTIPLE PARTITIONING IN CONTIGUOUS ALLOCATION
• Single contiguous allocation is inefficient as it limits computers to execute only one program at a time
resulting in wastage in memory space and CPU time.
• The problem of inefficient CPU use can be overcome using multiprogramming that allows more than
one program to run concurrently.
• In multiple partitioning, the OS needs to divide the available main memory into multiple parts to load
multiple processes into the main memory.
1. Variable size partitioning: In this policy, in starting, we treat the memory as a whole or a single chunk
whenever a process request for some space, exactly same space is allocated if possible and the
remaining space can be reused again.
2. Fixed Size Partitioning: We divide memory into fixed size partitions, which may be of different sizes,
but here if a process request for some space, then a partition is allocated entirely if possible, and the
remaining space will be wasted internally.
MEMORY ALLOCATION IN OS
Memory allocation is a process by which computer programs are assigned memory or space
It is of three types
1. First Fit Allocation The first hole that is big enough is allocated to the program.
2. Best Fit Allocation The smallest hole that is big enough is allocated to the program.
3. Worst Fit Allocation The largest hole that is big enough is allocated to the program.
NON-CONTIGUOUS MEMORY ALLOCATION
• It allows to load parts of a single process in a non contiguous fashion
• Thus, different parts of the same process can be stored at different places in the main memory
• Partial loading is allowed.
The problem of external fragmentation can be solved using Compaction: -
Advantages of Compaction
• Reduces external fragmentation.
• Make memory usage efficient.
• Memory becomes contiguous.
• Since memory becomes contiguous more processes can be loaded to memory
Disadvantages of Compaction
• System efficiency reduces.
• A huge amount of time is wasted in performing compaction.
• CPU sits idle for a long time.
• Not always easy to perform compaction.
NEED FOR PAGING
• The main disadvantage of Variable Partitioning is External fragmentation Although, this can be
removed by Compaction but compaction makes the system inefficient.
• Another way is non contiguous allocation.
Paging is a memory mgt scheme that permits the physical address space of a process to be non contiguous:
• Avoids external fragmentation
• Paging is a fixed size partitioning scheme
• In paging, secondary memory and main memory are divided into equal fixed size partitions
• The partitions of secondary memory are called as pages
• The partitions of main memory are called as frames.
MULTILEVEL PAGING: WORKING
• The page table having size greater than the frame size is divided into several parts
• The size of each part is same as frame size except possibly the last part
• The pages of page table are then stored in different frames of the main memory
• To keep track of the frames storing the pages of the divided page table, another page table is
maintained
• As a result, the hierarchy of page tables get generated
• Multilevel paging is done till the level is reached where the entire page table can be stored in a single
frame
SEGMENTATION
• Like Paging, Segmentation is another non contiguous memory allocation technique
• In segmentation, process is not divided blindly into fixed size pages but into modules
• Segmentation supports user’s view of memory
• Segmentation is a variable size partitioning scheme
• In segmentation, secondary memory and main memory are divided into partitions (called segments)
of unequal size
• The size of partitions depend on the length of modules
Segmented paging is a scheme that implements the combination of segmentation and paging.
• In Paging, process is divided into pages and in segmentation, process is divided into segments.
• In segmented paging, process is first divided into segments and then each segment is divided into
pages.
• These pages are then stored in the frames of main memory.
• A page table exists for each segment that keeps track of the frames storing the pages of that segment.
• Each page table occupies one frame in the main memory.
VIRTUAL MEMORY
• Paging was used to avoid memory fragmentation by breaking process into smaller pages and storing
them non contiguously in memory but the entire process still had to be stored in memory somewhere
• Practically, most processes do not need all their pages all at once because:
o Arrays are often oversized for worst case scenarios, so only a small fraction of arrays are used
in practice.
o Certain features of a program are rarely used like some functions, or routines.
• The ability to load only some pages of a process that were actually needed and only when they are
needed has several benefits.
o Programs could be written for a much larger address space than physically exists on the
o computer
o Because programs are only using a fraction of their total address space, there is more memory
left for other programs, improving CPU utilization and system throughput.
o Increases multiprogramming.
PURE DEMAND PAGING
• We can start executing a process with no pages in memory When the OS sets the instruction pointer
to the first instruction of the process, which is a non memory resident page, the process immediately
faults for the page.
• After the page is brought into memory, the process continues to execute, faulting as necessary until
every page that it needs is in memory At that it can execute with no more faults This scheme is called
pure demand paging.
DEMAND PAGING
• When a process is swapped in, its pages are not swapped in all at once They are swapped in only
when the process needs them (i e ON DEMAND)
• Known as lazy swapper.
• In paging, when a process is swapped in, the pager only loads into memory those pages that it expects
the process to need.
• Pages that are not loaded in memory are marked as invalid in the page table using an invalid bit.
• So, when a page is needed that was not originally loaded up, then a page fault trap is generated
Advantages
• A process can be larger than the main memory.
• More num of programs can be run at the same time as the use of main memory is less.
• Allows processes to share files easily and to implement shared memory Example Header files can be
common to multiple programs simultaneously Once loaded, can be shared among multiple programs.
Disadvantages
• Not easy to implement.
• May substantially decrease performance Thrashing.
Steps to handle page fault:
1. The memory address requested is checked first to make sure it was a valid memory request.
2. If the reference was invalid, the process is terminated Otherwise, the page must be paged in
3. A free frame is located.
4. A disk operation is scheduled to bring in the necessary page from the disk. (This will block the process
on an I/O wait, allowing some other process to use CPU in the meantime)
5. When the I/O operation is complete, the process page table is updated with the new frame number,
and the invalid bit is changed to the valid bit.
6. The instruction that caused page fault must now be restarted from the beginning.
PAGE REPLACEMENT ALGORITHMS
FIFO Page replacement
• Assumption The page that was brought in the longest time ago is the one that will not be needed
again for the longest future time.
• Although FIFO is simple and easy, it is not always optimal.
• An interesting effect that can occur with FIFO is Belady’s anomaly, in which increasing the number
of frames may increase the number of page faults
• Belady's anomaly happens in a FIFO scheme only when the page that is currently being referred is
the page that was removed last from the main memory.
Optimal page replacement
• The discovery of Belady's anomaly lead to the search for an optimal page replacement algorithm
which yields the lowest of all possible page faults, and which does not suffer from Belady's anomaly
• This algorithm is simply "Replace the page that will not be used for the longest time in the future.
LRU Page replacement
LRU is considered a good replacement policy and is often used.
Two simple approaches for its implementation
1. Counters: Every memory access increments a counter, and the current value of this counter is stored
in the page table entry for that page Then finding the LRU page involves simply searching the table
for the page with the smallest counter value
2. Stack: Another approach is to use a stack, and whenever a page is accessed, pull that page from the
middle of the stack and place it on the top The LRU page will always be at the bottom of the stack.
DEADLOCKS
A deadlock is a situation where each of the computer process waits for a resource which is being assigned
to some another process.
Necessary conditions for deadlocks: -
1. Mutual Exclusion A resource can only be shared in a mutually exclusive manner It implies two
processes cannot use the same resource at the same time.
2. Hold and Wait A process waits for some resources while holding another resource at the same time
3. No preemption A resource can be released only voluntarily by the task holding it, after that task has
completed its task.
4. Circular Wait All the processes must be waiting for the resources in a cyclic manner so that the last
process is waiting for the resource which is being held by the first process.
Disk Scheduling
SCAN
• The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until
it gets to the other end of the disk, where the head movement is reversed and servicing continues.
• It moves in both directions until both ends.
• Tends to stay more at the ends so more fair to the extreme cylinder requests.
LOOK
• The disk arm starts at the first I/O request on the disk, and moves toward the last I/O request on the
other end, servicing requests until it gets to the other extreme I/O request on the disk, where the
head movement is reversed and servicing continues.
• It moves in both directions until both last I/O requests; more inclined to serve the middle cylinder
requests.
CSCAN
The head moves from one end of the disk to the other, servicing requests as it goes. When it reaches the
other end, however, it immediately returns to the beginning of the disk, without servicing any requests on
the return trip.
C-LOOK
• Look version of C-Scan.
• Arm only goes as far as the last request in each direction, then reverses direction immediately,
without first going all the way to the end of the disk.
DISTRIBUTED OPERATING SYSTEM
A distributed operating system is system software over a collection of independent, networked,
communicating, and physically separate computational nodes.
NETWORK OPERATING SYSTEM
Network operating systems are server based operating systems that provide networking related
functionality. Its primary objective is to give local services to remote users. It's all nodes can have a different
operating system.
REMOTE PROCEDURE CALL (RPC) PROTOCOL IN DISTRIBUTED SYSTEM
1. Remote Procedure Call is a software communication protocol that one program can use to request a
service from a program located in another computer on a network without having to understand the
network's details.
2. RPC uses the client server model.
DFS
A distributed file system (DFS) is a file system with data stored on a server. The data is accessed and processed
as if it was stored on the local client machine.
There are various features of the DFS Some of them are as follows
1. Structure Transparency The client does not need to be aware of the number or location of file servers
and storage devices
2. Access Transparency Local and remote files must be accessible in the same method The file system
must automatically locate the accessed file and deliver it to the client
3. High availability support Some DFS systems also support very high availability by splitting and
replicating their control, metadata, and file data storage systems across multiple site
4. Simplicity and ease of use : The user interface of a file system should be simple and the number of
commands in the file should be small.
5. High reliability A file system should create backup copies of key files that can be used if the originals
are lost. Many file systems employ stable storage as a high reliability strategy.
DISTRIBUTED SHARED MEMORY (DSM) ARCHITECTURE
In computer science distributed shared memory DSM is a form of memory architecture where physically
separated memories can be addressed as a single shared address space.
1. Structure of shared memory space: It is layout of the shared data in memory It is normally dependent
on the type of application that the DSM system intended to support
2. Data location and access: To share data in a DSM system it should be possible to locate and retrieve
the data accesses by a user process.
3. Replacement strategy: Data block of the local memory must be replaced by a new data block
SERVERS: STATELESS AND STATEFUL
A Stateful server remember client data (state) from one request to the next Stateful servers, do store session
state.
A Stateless server keeps no state information Stateless file servers do not store any session state.
FTP (File Transfer Protocol), Telnet, MongoDB, Cassandra, and MySQL are the example of Stateful applications
HTTP (Hypertext Transfer Protocol), UDP (User Datagram Protocol), DNS (Domain Name System) are the
example of Stateless Protocol.