0% found this document useful (0 votes)
2 views17 pages

Os Complete Notes

The document provides an overview of operating systems (OS), detailing their functions, types, and services such as process and memory management, file system operations, and device management. It explains key concepts like processes, threads, scheduling algorithms, and inter-process communication, along with issues like deadlocks and race conditions. Additionally, it discusses CPU scheduling strategies and their goals, emphasizing the importance of resource allocation and security in OS operations.

Uploaded by

vivekberma01780
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)
2 views17 pages

Os Complete Notes

The document provides an overview of operating systems (OS), detailing their functions, types, and services such as process and memory management, file system operations, and device management. It explains key concepts like processes, threads, scheduling algorithms, and inter-process communication, along with issues like deadlocks and race conditions. Additionally, it discusses CPU scheduling strategies and their goals, emphasizing the importance of resource allocation and security in OS operations.

Uploaded by

vivekberma01780
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/ 17

Basics of OS

Process Management Process, PCB, States Scheduling Algorithms (FCFS, SJF, Round
Robin, Priority) Threads & Multithreading Inter-Process Communication (IPC)
Deadlocks Conditions, Prevention, Avoidance (Banker’s), Detection, Recovery
Memory Management Paging, Segmentation Virtual Memory, Page Replacement
(FIFO, LRU, Optimal) File System File Allocation (Contiguous, Linked, Indexed)
Directory Structure Disk Scheduling Algorithms FCFS, SSTF, SCAN, C-SCAN I/O
Management System Calls Synchronization Critical Section, Semaphores, Mutex

🔹 What is an Operating System? An Operating System


(OS) is a software that acts like a manager between the
user and the computer hardware.

🔹 Functions of OS: Process Management – Manages


running programs (processes)
Memory Management – Controls RAM usage

File Management – Controls data and file storage

Device Management – Manages input/output devices (keyboard, mouse)

Security – Protects system from unauthorized access

User Interface – CLI (Command Line) or GUI (Graphical UI)

🔹 Types of OS: Batch OS – No interaction with user (e.g.,


early computers)
Time-Sharing OS – Many users at the same time

Real-Time OS – Quick response time (used in robots, airbag systems)

Distributed OS – Uses multiple computers as one system

Network OS – Manages networked computers

Mobile OS – Android, iOS


🔧 OS Services (Operating System Services) The OS
provides several services to make using the computer
easier for the user and applications.
These services help the system work smoothly, safely, and efficiently.

✅ 1. Program Execution The OS helps to load and run programs


(applications).
It also stops them properly after finishing.

🔸 Example: When you open MS Word, the OS loads it and starts its
execution.

✅ 2. I/O Operations (Input/Output) OS allows programs to read


input (like from keyboard, mouse) and write output (like to screen
or printer).

🔸 Example: Typing on keyboard (input), displaying on screen


(output).

✅ 3. File System Manipulation The OS manages files and folders —


create, delete, read, write, rename, etc.

🔸 Example: Opening or saving a file in MS Word.

✅ 4. Communication (Inter-Process Communication) If one


process wants to talk to another process, the OS allows it through
IPC (Inter-Process Communication).

🔸 Example: A media player getting sound from the audio driver


process.

✅ 5. Error Detection OS constantly checks for errors in CPU,


memory, I/O devices, etc.
It tries to correct or report them.

🔸 Example: “Printer not connected” error is detected by OS.


✅ 6. Resource Allocation OS gives CPU time, memory, and I/O
devices to programs fairly and efficiently.

🔸 Example: If two apps are open, OS decides how much CPU each
gets.

✅ 7. Security and Protection OS protects data from unauthorized


access and provides user authentication.

🔸 Example: Login with a password, or restricting file access to


certain users.

Summary (Short Notes): Service Name Description Program


Execution Load and run applications I/O Operations Manage
input/output devices File Manipulation Create, delete, read, write
files Communication (IPC) Allow processes to talk to each other
Error Detection Find and fix system problems Resource Allocation
Divide CPU, memory, etc. fairly Security & Protection Protect user
data and restrict access

🧩 1. System Call 🔹 What is it? A System Call is a way for a


program to ask the Operating System to do something.
Programs can't directly talk to the hardware (like memory, disk, CPU), so they use
system calls to request services from the OS.

🔹 Example: When a program wants to:


Read a file → it uses a read() system call

Write to a file → it uses write() system call

Create a new process → fork()

Allocate memory → malloc() (which internally uses system calls)

🔹 Categories of System Calls: Category Examples Process


Control fork(), exit(), wait() File Management open(),
read(), write(), close() Device Management ioctl(), read(),
write() Information Maintenance getpid(), alarm(), time()
Communication pipe(), send(), recv()

🔹 Simple Analogy: 🔑 Think of the OS as a hotel manager,


and the program is a guest. The guest uses system calls
(like requests) to ask for room service, cleaning, food, etc.

💻 2. System Program 🔹 What is it? System Programs are


software tools that provide a user-friendly environment to
interact with the computer and OS.
They are not part of the OS kernel, but they support its operation.

🔹 Examples of System Programs: File Management tools –


cp, mv, rm, mkdir
Editors – nano, vim, notepad

Compilers – gcc, javac

Debuggers – gdb

Shells – bash, cmd, PowerShell

🔹 Key Difference: Feature System Call System Program


Definition Interface between program and OS Utility
programs provided by OS Level Low-level (close to kernel)
High-level (user-facing tools) Used by Programs Users and
programs Examples read(), write(), fork() ls, cp, nano, gcc,
cmd
✅ Summary: System Call = Program’s request to OS (like asking
for file, memory, or device access)
System Program = Helpful tools provided by OS to users (like editors, compilers, file
tools)
🧠 What is a Process? A process is a program in execution.
When you run a program (like MS Word or a calculator), the operating system
creates a process to run it.

🔸 Example: notepad.exe is a program (just a file on disk).


When you double-click it, it becomes a process (loaded into memory and running).

🧩 Difference between Program and Process: Program


Process Passive (on disk) Active (in memory) Just code
Code + execution state Doesn't use resources Uses CPU,
memory, etc.
🏃‍♂️ Process States A process can be in different states during its life:
State Description New Process is being created Ready Waiting to be assigned to CPU
Running Instructions are being executed Waiting Waiting for some event (like I/O)
Terminated Process has finished

📘 Diagram:
sql Copy Edit New → Ready → Running → Terminated
↓↑
Waiting ← 📋 Process Control Block (PCB) Each process is represented by a PCB,
which stores information about the process.

🔸 PCB Contains: Process ID (PID) – Unique number


Process State – Ready, Running, etc.

Program Counter – Next instruction to execute

CPU Registers

Memory Info – Which memory the process is using

I/O Info – Which files/devices it's using

📝 Think of PCB like the profile of a process.


🔗 Process vs Thread (Quick View) Process Thread
Independent Part of a process Own memory Share
memory with other threads Heavy Lightweight
✅ Summary: A process is a running program.
OS manages processes using a PCB.

Process can be in 5 states: New, Ready, Running, Waiting,


Terminated.

🔄 What is Context Switching? Context Switching is the


process of saving the state of one process and loading the
state of another so that the CPU can switch from one
process to another.
🔸 In simple words: When the CPU stops working on one task
(process) and starts another, the OS saves the first task's current
state and loads the second task’s previous state.

📘 Example: Let’s say:


Process A is running

Then, Process B becomes ready and needs to run

OS will:
Save A's current state in its PCB Load B's state from its PCB Give CPU to B This is
called context switch.

🧠 Why is it needed? For Multitasking – Many processes


share one CPU For Fairness – So all processes get a turn
For Interrupt handling – If a higher-priority task arrives

📋 What gets saved/restored in a context switch? Program


Counter (PC) – Which instruction to execute next
CPU Registers

Process State (Running, Ready, etc.)

Memory information

📦 All this is stored in the Process Control Block (PCB).

🐌 Is context switching slow? Yes, it takes time (called context


switch overhead) because: CPU must save and load a lot of data No
useful work is done during this switch
But it's necessary for multitasking.

📝 Summary: Feature Explanation Definition Switching CPU from


one process to another Done by Operating System Uses Process
Control Block (PCB) Purpose Multitasking, responsiveness
Overhead Takes time and resources

📊 Small Diagram: css Copy Edit [Running Process A] ↓


Save context (A) ↓ Load context (B) [Running Process B]
Would you like to go next to Scheduling Algorithms (FCFS,
SJF, etc.) or cover Threads and Multithreading?

⚙️ Operations on Process The Operating System performs


several operations on processes during their lifetime. The
main operations are:
✅ 1. Process Creation When a new process is created, it is added
to the system and given resources (like memory, PID, etc.).

🔸 Reasons for Process Creation: A user starts a program (e.g.,


opening MS Word)
A process creates another process (called child process)

🔸 System Call Used: fork() in UNIX/Linux — creates a new child


process
CreateProcess() in Windows

✅ 2. Process Execution After creation, the process enters the


ready state. When the CPU is available, the OS schedules it and
moves it to the running state.
The process runs its instructions with help from the CPU and OS.

✅ 3. Process Suspension (Waiting) A process might not always be


able to run. Sometimes it waits for:
Input from keyboard/mouse File to open Data to be read from disk In this case, it
moves to the waiting/blocking state.

✅ 4. Process Resumption Once the required event happens (e.g.,


input is received), the waiting process becomes ready again and
waits for CPU time.

✅ 5. Process Termination After finishing its task, the process


terminates (ends).

🔸 Reasons for Termination: Process completed successfully Error


occurred (like divide by zero) Terminated by user or OS
The OS then frees the resources used by the process.

✅ 6. Process Scheduling While processes are running, the OS


constantly switches between them using scheduling algorithms
(like FCFS, SJF, Round Robin) to decide who runs next.

🔁 Parent and Child Processes The process that creates another is called the Parent.

The new one is the Child.

The OS keeps track of all parent-child relationships.

📝 Summary: Operation Description Create Start a new process


Execute Run the process Wait/Suspend Pause for I/O or event
Resume Continue running after waiting Terminate End the process
and free resources
🧵 What is a Thread? A thread is the smallest unit of execution inside a process.

A process can have one or more threads. All threads in the same process share the
same memory and resources.

🔸 Example: When you open a web browser: One thread loads the
page One thread handles user clicks One thread plays video
All these threads work together in the same process.

🧩 Difference between Process and Thread Feature


Process Thread Definition Program in execution Small
task inside a process Memory Has its own memory Shares
memory with other threads Communication Slower (need
IPC) Faster (shared memory) Creation Time Slow Fast
Overhead High Low

🔧 Thread Operations (Management) The OS performs


these main operations on threads:
✅ 1. Thread Creation A new thread is started inside an existing
process.
Uses system calls like pthread_create() in Linux.

✅ 2. Thread Scheduling OS decides which thread to run next using


scheduling (just like with processes).
Threads of the same process may run in parallel on multi-core CPUs.

✅ 3. Thread Synchronization Since threads share memory, race


conditions may happen (two threads trying to change the same
variable at the same time).

We use tools like:


Mutex (Mutual Exclusion)

Semaphores
Locks To avoid conflicts.

✅ 4. Thread Termination A thread ends after completing its task.


Can also be terminated early by the process or another thread.

👥 Types of Threads
User-Level Threads (ULT) Managed by the user (not the OS).

Fast to create but less powerful.

Kernel-Level Threads (KLT) Managed by the Operating System.

Slower to create but better control and performance.

🧵 Multithreading Multithreading is a technique where multiple threads run in the


same process to do tasks faster.

🔸 Advantages: Faster performance


Better CPU usage

Easier to manage related tasks

📝 Summary Table: Feature Description Thread Smallest unit of


CPU execution Belongs to A process Shares Memory, files,
resources of process Managed by OS or User Key operations Create,
Schedule, Synchronize, Terminate Used in Web servers, browsers,
games, OS tasks
These are the problems that occur when multiple threads run together and share
data or resources.

⚠️ Common Threading Issues ✅ 1. Race Condition When


two or more threads try to change the same data at the
same time, the result becomes unpredictable.
🔸 Example: Two threads both increase a bank balance by ₹100 —
but the final result may only show ₹100 instead of ₹200.
🔹 Why it happens? Both threads read the same old value
before either updates it. They overwrite each other’s
changes.
✅ 2. Deadlock When two or more threads wait forever for each
other to release resources, and none of them can continue.

🔸 Example: Thread A has resource X, and waits for Y. Thread B has


resource Y, and waits for X. Both are stuck forever.

✅ 3. Starvation When a thread waits too long to get CPU or


resources because other threads keep getting them first.

🔸 Example: A low-priority thread never gets a turn because high-


priority threads keep running.

✅ 4. Livelock Similar to deadlock, but threads keep changing their


state to avoid deadlock, yet no thread makes progress.

🔸 Example: Two threads politely step aside for each other again
and again — but never proceed.

✅ 5. Priority Inversion A low-priority thread holds a resource


needed by a high-priority thread, but the high-priority thread has
to wait.

🔸 Example: Low-priority thread has a lock. High-priority thread


needs it. But OS keeps giving CPU to other high-priority threads.
Low-priority thread never finishes, and high-priority thread waits forever.

🛡️ How to Prevent or Fix Threading Issues Problem


Solution Race Condition Use mutex, locks, semaphores
Deadlock Avoid circular wait, use lock ordering Starvation
Use fair scheduling Livelock Add delays, backoff strategies
Priority Inversion Use priority inheritance protocol
📝 Summary: Issue Description Race Condition Threads changing
data at once Deadlock Threads waiting forever Starvation Thread
waits too long Livelock Threads keep changing, no work Priority
Inversion Low thread blocks high one

🧠 What is CPU Scheduling? The CPU can run only one


process at a time (in single-core systems), but there are
many processes ready to run. So, the OS must decide which
process gets the CPU next — this is called CPU scheduling.
🔁 The part of the OS that does this is called the CPU Scheduler.

🧩 When does CPU Scheduling happen? Process switches


from running to waiting (e.g., for I/O) Process finishes
Interrupt occurs Time slice is over (in time-sharing
systems)

🎯 Goals of CPU Scheduling: Maximize CPU usage (keep it


busy) Maximize throughput (more processes finish
quickly) Minimize waiting time Minimize response time
(how fast the system responds) Fairness (each process
gets a turn)

📋 Types of CPU Scheduling Algorithms Algorithm Type


Description FCFS (First Come First Serve) Non-preemptive
Runs in order of arrival SJF (Shortest Job First) Non-
preemptive or Preemptive Runs shortest process first
Priority Scheduling Can be both Runs highest priority first
Round Robin (RR) Preemptive Gives each process a time
slice Multilevel Queue Both Different queues for different
types of processes Multilevel Feedback Queue Preemptive
Processes can move between queues
🔹 1. FCFS (First Come First Serve) Processes are executed
in the order they arrive Simple but can cause long waiting
times
🕒 Example: Process Burst Time P1 5 P2 3 P3 8 They run in the
order: P1 → P2 → P3

🔹 2. SJF (Shortest Job First) Process with the shortest


burst time is executed first Minimum average waiting time
Can cause starvation for long processes

🔹 3. Priority Scheduling Each process is given a priority


Higher priority = scheduled first Can be preemptive or
non-preemptive Problem: Starvation (low priority may
wait forever) 🔹 4. Round Robin (RR) Each process gets a
fixed time slice (quantum) to run
After time is over, it goes back to the ready queue

Preemptive and used in time-sharing systems

✅ Fair to all, but may have high waiting time if quantum is too
small

🧠 Important Terms: Term Meaning Burst Time Time


needed by process to run Waiting Time Time process
waits in ready queue Turnaround Time Waiting Time +
Burst Time Response Time Time from request to first
response
📝 Summary: CPU scheduling decides which process gets CPU time
Main algorithms: FCFS, SJF, Priority, RR Preemptive: Can switch
processes (e.g., RR) Non-preemptive: Runs to completion (e.g.,
FCFS) Goals: fairness, speed, efficiency
Make this a word document use color coding for headings and subheadings and
points
Comparison: Process vs Thread
Feature Process Thread
Definition Program in execution Small task inside a process
Memory Has its own memory Shares memory with other
threads
Communication Slower (need IPC) Faster (shared memory)
Creation Time Slow Fast
Overhead High Low
Diagram: Process State Transition
Use this structure to draw:
New → Ready → Running → Terminated

↓ ↑

Waiting ←———————————
Comparison: CPU Scheduling Algorithms
Algorithm Type Preemption Notes
FCFS Non-preemptive No Runs in order of
arrival
SJF Both Optional Runs shortest job
first
Priority Both Optional Higher priority runs
first
Round Robin Preemptive Yes Each gets a time
slice
Multilevel Queue Both Depends Different queues for
process types
Multilevel Feedback Preemptive Yes Processes can move
between queues

You might also like