






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































8 Core Modules From Batch & Real-Time OS to Context Switching & PCBs
Key Algorithms SRTF, Round Robin, MFQS, Banker's, FIFO, Optimal & LRU
36 Study Pages Clear bulleted notes, code snippets & state diagrams
Structured Navigation • Verified Page Index 38 Pages Total
O P E R AT I N G S Y S T E M S S T U DY G U I D E
Table of Contents (^) 8 Modules • Pages 3–
OS Definition & Examples Needs of an Operating System Core OS Functions
Batch & Multi-Program OS Time-Sharing & Parallel OS Distributed OS & Real-Time Systems
p
Process, Threads & 5-State Model Systems Concepts & Virtual Machines System Calls: Types & Needs
Preemptive & Non-Preemptive Algorithms Multilevel Feedback Queue (MFQS) Gantt Chart Representation
Race Condition & Critical Section Semaphores & Producer–Consumer Deadlock & Four Necessary Conditions Prevention, Banker's Algo & Recovery
Memory Management & Addressing Swapping & Fragmentation Paging, Demand Paging & Replacement Virtual Memory & Segmentation
Organization, Access & FS Types File Directories & Structures Contiguous, Linked & Indexed Allocation
Process Lifecycle & State Diagram Process Control Block (PCB) Scheduling Queues & Context Switching
Navigation Tip: Use the PDF Bookmarks sidebar to jump directly to any module or subtopic.
Complete Edition
● Manages User Interface ● Handle Error ● Support Network
Types of Operating System
1. Batch OS: ● The Batch OS is an early type of OS that processes similar jobs in a batch or a group without user direct interaction. ● Users submit a job to an operator who groups similar jobs into a batch and runs them one after another, used in the 1950s - 1970s for scientific calculation. Working: ● Users submit jobs to an operator. ● The operator groups similar jobs and loads them onto the system. ● The OS processes one job at a time automatically without user interaction. ● The output is produced after the execution, which the user collects. 2. Multi Program OS: ● Multi Program OS allows multiple jobs to be located into memory and executed simultaneously, CPU switching between jobs when one job is waiting for input/output operation. Maximizing resource utilization. ● Developed in late 1970s, used in industry and research organizations to include efficiency. ● Modern OS concepts like multitask from this system evolved. Working: ● Multiple jobs are loaded in memory at same time. ● The CPU starts executing one job while the other waits. ● When a job needs I/O operation, the CPU switches another job. ● This cycle continues and ensures the CPU never idle.
● Once jobs are completed the output is provided to the user.
3. Time Sharing OS:
● It allows many users to share the computer simultaneously. ● The CPU executes multiple jobs by switching among them, but the switches occur so frequently that each user is given the impression that the computer system is dedicated to his/her use, even though it is being shared among many users. Working: ● Multiple user programs are loaded into memory at the same time. ● The CPU assigns a short time slice to each program. ● After one slice the CPU reaches to the next slice and switches to the next program even if the previous one is not finished. ● The cycle repeats so far that the user thinks their programs are running simultaneously. ● If the program finishes earlier it is slot given to another task.
4. Parallel Operating System:
● Parallel OS allows multiple processors(CPU) to work together on different parts of a task simultaneously, increasing speed & efficiency. ● These systems are used in high performing computing where large amounts of data need to be processed quickly. ● Developed in late 1980s for scientific research difference and super computer. ● Used in industries that require high speed processing like live weather forecasting, AI research etc. ● It is widely used in modern multiple core processor & cloud computing.
Working: ● A task divided into smaller sub-task. ● Different computers in the network process different sub-tasks. ● The computers communicate and share data through the network. ● The final result combined and presented to the user.
6. Real Time System:
● It is designed to process tasks immediately with minimal delay. ● It is used in systems where timing is critical such as medical devices, aviation and robotics. ● Used for industrial automation, military systems and medical devices. ● Used today in self driving cars, pacemakers and real time analytics.
Type of Real Time System:
1. Hard: Strict timing rules. Ex:- airbags deployment in cars. 2. Soft: Delays are acceptable but not idle. Ex:- Video streaming.
Working: ● Receives an input (sensor data, user commands etc). ● Processes it instantly without any delay. ● Generates an immediate output to control a device or system. ● Ensures predictable response time making it reliable for time sensitive tasks.
Process
Running an instance of a program or a program in execution is known as
process.
Threads
Multiple parts of a process that run together are known as thread.
5 States Process Model
In 5 states process model the states has been split into two non-running
status:
(i) Ready (ii) Blocked
And along with these two more states are added:
(i) new (ii) exit
Running: It means the process is currently being executed.
Ready: It means a process is prepared to execute when given the
opportunity by the OS.
System Calls
● A system call is a request made by a user program to the OS to perform some task like file operation, process management, services communication etc. ● Since user programs cannot directly access hardware.
Types of System Calls:
1. Process Control: Create, execute and terminate processes. Ex:- exec(); 2. File Management: Open, read, write and close files. Ex:- write(); 3. Device Management: Interact with hardware. Ex:- ioctl(); 4. Information Maintenance: Get system / process info. Ex:- time(); 5. Interprocess Communication: Send / receive messages. Ex:- msgsend();
Needs of System Calls:
● Resource Management: Access to CPU, memory, files, and devices. ● Security: Protection of the OS and other programs from malicious or faulty applications. ● Abstraction: Simplification of complex hardware interactions for programmers. ● Process Management: Creation, termination, and communication between programs.
CPU Scheduling Algorithm
● CPU scheduling is the process of deciding which process gets the CPU when multiple processes are waiting in the ready queue. ● It helps in efficient CPU utilization and ensures fair execution of processes.
Types of CPU Scheduling:
1. Preemptive Scheduling: The CPU can switch from one process to another before the first process is finished. Types of Preemptive Scheduling: ● SRTF (Shortest Remaining Time First): Choose the process with the least burst time. ● LRTF (Longest Remaining Time First): Choose the process with the most burst time. ● RR (Round Robin): Each process gets a fixed time quantum in a cyclic order. ● Priority Scheduling: Highest priority process preempts the current one. 2. Non-Preemptive Scheduling: Once the process gets the CPU, it runs until it finishes or gives up. Types of Non-preemptive Scheduling: ● FCFS (First Come First Served) ● SJF (Shortest Job First) ● LJF (Longest Job First) ● Priority Based
Gantt Chart
● A gantt chart is a visual representation of scheduling showing the execution of processes over time. ● It helps in understanding CPU scheduling by displaying when each process starts and ends.
Process Synchronization
● Process synchronization ensures that multiple processes can access and use shared resources in a coordinated and orderly manner, preventing conflicts and maintaining data consistency.
Types of Process:
1. Independent Process: An independent process is a process that does not share data, files, memory or any resources with any other process. Ex:- A calculator app running while you are typing in a notepad. 2. Cooperative Process: A cooperative process is a process that can affect or be affected by other processes. It shares data, memory or resources with other processors. Ex:- One process writes to a file while another reads it.
Race Condition
int s = 5;
P1 P
int x = s; int y = s;
X++; y--;
sleep(1); sleep(1);
s = x; s = y;
(terminate) (terminate)
● When multiple processes run concurrently and try to access shared resources, it can lead to problems like: ● (1)Race condition (2)Data inconsistency (3)Deadlock
Critical Section Problem
● In a multitasking system, multiple processes or threads may need to access shared resources such as (files, variables, printers, I/O devices). ● If multiple processes access these resources simultaneously, it can lead to Data Inconsistency, System Crashes and Unexpected behavior or Incorrect Results.
Structure of Process Execution
do {
Entry section Critical section Exit section
} while(true);
● Entry Section: Code that ensures only one process can enter the critical section at a time. ● Critical Section: It is part of the program where the shared resource is accessed. ● Exit Section: Code that releases the resource or lock.
Problems if multiple processes enters the critical section:
1. Change data incorrectly. 2. Cause crash. 3. Create unexpected results.
● Signal: After the process is finished, it increases the semaphore value. This allows other waiting processes to enter.
int s = 5; //(number of resources available)
wait(s) { signal(s){
while(s<=0); s=s+1; s=s-1; } }
Classical problems of Synchronization:
Case 1: Consumer - Producer Problems:
● A consumer - producer problem is a classical problem of synchronization in operating systems. ● It describes two processes: consumer and producer that share a fixed sized buffer. ● The producer generates data and puts it into the buffer. ● The consumer takes the data out of the buffer and processes it.
Case 2:
● The buffer already has 3 items. ● The producer starts adding the 4th item and begins increasing the count. ● Before finishing, it gets preempted (paused). ● Meanwhile, the consumer starts removing an item and begins decreasing the count. ● But before completing, the consumer also gets preempted. ● When both processes resume, they finish their updates without knowing about each other's changes. ● This leads to an incorrect count , creating a race condition.
Deadlock
● A deadlock is a situation in an OS where two or more processes are stuck waiting for resources and none of them can continue because they are waiting on each other. ● Ex:- P1 has R1 and wants R2. P2 has R2 and wants R1. Both are waiting other to release a resource but neither will do that so they get in a deadlock.
Four conditions to deadlock occur:
1. Mutual Exclusion: Only one process can use resources at a time. 2. Hold and Wait: A process holding one resource and waiting for another. 3. No-Preemption: Resources cannot be forcibly taken away. 4. Circular Wait: A circular chain of processes waiting for each other's resources.
2. Deadlock Prevention:
● It is the strategy where the OS ensures that at least one of the necessary conditions for deadlock cannot hold true, so deadlock can be prevented from occurring. (Eliminate mutual exclusion, eliminate hold and wait, eliminate no-preemption, eliminate circular wait).
3. Deadlock Avoidance:
● Deadlock avoidance means the operating system carefully decides whether to give resources to processes, by checking if it would lead to a deadlock in future. ● It asks processes to tell in advance how many resources they might need. Then using methods like Banker’s algorithm it only allows requests if the system will stay in a safe state (where every process can finish its work one by one). ● Banker’s Algorithm: It is a deadlock avoidance or deadlock detection method where each process tells the system the maximum resources it might need. ● When a process asks for resources the system checks: (i) If giving them will still keep the system in safe state. (ii) If yes, the resources are given, If no, the process must wait.
4. Deadlock Detection and Recovery:
● Deadlock can happen when multiple processes are running together and competing for resources, the system needs a way to detect when a deadlock has occurred. It is a deadlock detection.
Algorithms used for deadlock detection:
1. RAG (Resource Allocation Graph) 2. WFG (Wait For Graph) 3. Banker’s Algorithm
Deadlock Recovery:
● Once an OS detects a deadlock, it needs to recover from it to break the deadlock and let the process continue. ● Methods of Recovery: (i) Process Termination: End one or more processes involved in the deadlock. (ii) Resource Preemption: Temporary take the resources from one process and give it to another process to resolve the deadlock. (iii) Rollback: Roll a process back to a safe state and restart it.