Operating System
syllabus:
1)Basic introduction
Definition of os , types of os, process diagram , system
cal.
2)process scheduling
Fifo , sjf, round-robin
3)process synchronization
semaphore
4)deadlocks & threads (theoritical mostlty)
Banker’s algorithm
5)memory management
Pajing , segmentation , fragmentation , virtual memory ,
page replacement algorithm .
6)disk scheduling
scan , cscan , fcfs,ls ,mkdir , cd , chmod , open system
call
7)UNIX commands
Sequential axis , random axis , linked axis
8)file management & security
Virus , vulnearability , encryption , loopholes , attacks .
📘 1) Basic Introduction
🧠 What is an Operating System (OS)?
An Operating System is the software that lets you interact with
your computer and manages hardware like CPU, memory, and
storage.
🧺 Real-Life Analogy: The OS is like a manager in a restaurant
who ensures chefs, waiters, and customers work smoothly.
🖥️ Types of Operating Systems:
Type Example Use Case
Batch OS Early IBM systems Jobs run without user interaction
Time-Sharing OS UNIX Multiple users access system
together
Real-Time OS RTOS in medical Responds quickly to input
devices
Distributed OS Google servers Multiple computers act as one
system
Mobile OS Android, iOS For smartphones
Network OS Windows Server, Manages network resources
Novell NetWare
🔁 Process Diagram:
A process is a program in execution.
Process States (diagram):
CopyEdit
New → Ready → Running → Waiting → Terminated
↑ ↓
← ← ← ← ← ←
● New: Program loaded into memory.
● Ready: Waiting to run.
● Running: Executing.
● Waiting: Waiting for I/O.
● Terminated: Finished execution.
📞 System Calls:
System calls are like requests from programs to the OS.
System Call What It Does
open() Open a file
read() Read from a file
write() Write to a file
exit() Terminate program
fork() Create new process
⏳ 2) Process Scheduling
When multiple processes want to run, the OS schedules them.
🔄 Common Scheduling Algorithms:
Algorithm Description Example
FIFO First-In, First-Out Like a queue at a ticket
counter
SJF Shortest Job First Short tasks finish early
Round Robin Each process gets equal Like kids taking turns playing
time slices a game
🔐 3) Process Synchronization
When multiple processes access shared data, we need
synchronization.
⛔ Semaphore:
A variable that controls access.
● Binary Semaphore: 0 or 1 (locked/unlocked)
● Counting Semaphore: Allows limited entries (e.g., 3
printers)
🧃 Example: Think of a water cooler with 1 cup — only one person
can use it at a time. Semaphore prevents two people from trying
at once.
☠️ 4) Deadlocks & Threads
🔁 Deadlock:
When two or more processes wait forever for each other.
🎬 Example: Process A has a camera and wants a mic. Process B
has a mic and wants a camera. Both are stuck waiting = deadlock.
👥 Threads:
● Lightweight processes.
● Share memory and resources.
📦 Example: A web browser opens tabs using threads — each tab
runs separately but within the same application.
💰 Banker’s Algorithm (For Deadlock Avoidance):
● Ensures system never enters unsafe state.
● Like a bank that gives loans only if it knows it can
satisfy all users safely.
💾 5) Memory Management
📦 Paging:
Breaks memory into fixed-size blocks (pages). Helps with better
memory usage.
🧩 Segmentation:
Divides memory based on logical parts (code, stack, data).
❌ Fragmentation:
● Internal: Wasted space inside memory block.
● External: Gaps between used memory blocks.
🧠 Virtual Memory:
Allows a system to use disk space as extra RAM. Slower but
helpful when RAM is full.
🔄 Page Replacement Algorithms:
Used when memory is full — decides which page to remove:
Algorithm Description
FIFO Remove oldest page
LRU Least Recently Used
Optimal Future-based (ideal but theoretical)
📀 6) Disk Scheduling
Decides the order to access disk I/O requests.
Algorithm Description
FCFS First-come, first-served
SCAN Like an elevator — up, then down
C-SCAN Circular — always moves one direction
LOOK Moves only as far as needed
🧾 Some System Calls:
Command Use
mkdir Make a directory
cd Change directory
chmod Change file permissions
open() Open a file
🐧 7) UNIX Commands
Concept Meaning & Example
Sequential Access Read/write in order. Like a playlist. Use: cat, more
Random Access Jump to any point. Like a movie player. Use: head,
tail, seek()
Linked Access Access through links. Like hyperlinks. Use: ln, ls
-i, linked lists in files
🔐 8) File Management & Security
📁 File Management:
Organizing and controlling access to files using the OS.
🛡️ Security Concepts:
Concept Explanation
Virus Malicious code that replicates itself
Vulnerability Weakness in system security (e.g., open port)
Encryption Scrambles data using keys so only trusted users can
read it
Loopholes Bugs attackers exploit
Attacks Methods used by hackers (phishing, ransomware, etc.)
Operating System and its Functions
Operating system is a system software , it works as an
interface b/w user and hardware(CPU , I/O devices , RAM) .
If OS not there , then you need to repeatedly write program for
each devices to access them .
to print only , first write program to invoke printer then the
job to print is another task.
As user directly accessing hardware , so if user1 is accessing
CPU , now user2 wants to use but user1 is not releasing it .
OS examples : windows , macOS
Why use? To provide convienience to user .
windows → convienience to user
Throughput→ number of tasks executed per unit time.(eg. linux).
Functionalities of OS:
1)resource manager/governer
Where parallel access (multiple user applying requests to a
particular data)
2)process management .(CPU Scheduling)
3) storage management
4)memory management (RAM)
5)security
🖥️ What is an Operating System (OS)?
An Operating System is a type of system software that acts as a
bridge (interface) between:
● 🧑 The user (you)
● 💻 The computer hardware (CPU, RAM, printer, keyboard,
etc.)
❓ Why is the OS important?
If you don’t have an OS, you’d have to:
● Write your own code every time you want to use the printer,
mouse, or display.
● You'd need to know how the hardware works and manually give
commands in machine language.
🖨️ Real-Life Example:
Want to print a document?
Without OS:
● You write a program to communicate with the printer.
● Then write another program to send the print data.
● Every user must know how to write this code!
With OS:
● You just click “Print”.
● OS handles all the communication with the printer.
🔒 Example of Resource Conflict (No OS):
Imagine User1 is using the CPU to run a program.
● Now User2 also wants to run a program.
● But since there’s no OS, User1 doesn’t release the CPU.
● Now User2 is stuck — because there’s no system to manage or
share the CPU.
This is where the OS helps — it manages who gets to use
resources and for how long.
🌟 Why do we use an OS?
To make life easy for users and to make the system:
● Convenient
● Fast
● Secure
● Efficient
📱 OS Examples:
Device OS Example
PC Windows, macOS
Phone Android, iOS
Servers Linux, UNIX
🚀 Throughput:
Throughput = number of tasks completed in a given time
💡 Example: A Linux server running 100 programs per minute has
high throughput.
🧠 Functionalities of OS
1. 🧩 Resource Manager (Governor)
● OS manages shared resources like CPU, RAM, files, printer,
etc.
● It ensures that multiple users or programs can access
resources without conflict.
📚 Example:
● You and your friend both want to open a file on a shared
drive.
● OS locks it for one user at a time to avoid data mess.
2. ⚙️ Process Management (CPU Scheduling)
● When many programs are running (browser, music player,
Word), the OS decides:
○ Who gets the CPU?
○ For how long?
○ In what order?
🕹️ Example:
● OS switches between apps quickly — feels like they’re all
running together (multitasking), but the CPU handles them
one by one very fast.
3. 💽 Storage Management
● OS manages files on hard drives, SSDs, pen drives, etc.
● It decides:
○ Where to store files
○ How to retrieve them
○ Organizes data in folders/directories
🗂️ Example:
● When you save a photo, OS decides where and how to store
it.
4. 🧠 Memory Management (RAM)
● OS decides:
○ Which program gets how much RAM?
○ What happens if RAM is full? (Uses virtual memory)
○ Frees memory when a program ends
💡 Example:
● You open 5 apps → OS splits RAM between them.
● If RAM is full, OS stores unused parts temporarily on the
disk.
5. 🔐 Security
● OS ensures:
○ Only authorized users can log in
○ Files and data are protected
○ Prevents malware or viruses from damaging the system
🔑 Example:
● Login password, file permissions, antivirus — all managed
by the OS.
🌐 What is an Operating System (OS)?
An Operating System (OS) is the main software that acts as a
bridge between the user and the computer hardware.
Think of it like:
OS is the manager of your computer — it tells hardware
(CPU, RAM, disk, etc.) what to do, and helps programs
run smoothly.
● Without an OS, your computer is just a box of parts that
don’t know how to talk to each other.
● The OS helps run applications, manage files, and control
hardware like your keyboard, mouse, display, etc.
🖥️ Examples of Operating Systems:
Device Type Operating System Examples
Desktop / Laptop Windows, macOS, Linux (Ubuntu, Fedora)
Smartphones Android, iOS
Servers Linux (Red Hat, CentOS), Windows Server
IoT Devices TinyOS, FreeRTOS, embedded Linux
🛠️ What Does an OS Do?
Function Example
User Interface Shows a screen with icons, menus (like Windows
desktop or Android home screen)
Program Execution Runs apps like Chrome, games, MS Word
File Management Saves, opens, deletes files (like a photo in
your gallery or a document on desktop)
Device Control Talks to your mouse, keyboard, printer, etc.
Memory Management Decides which app uses how much RAM
Security Manages users, passwords, and blocks harmful
access
❌ What if there was No OS?
Imagine trying to use a smartphone or laptop without Android,
iOS, or Windows. It’s like buying a car without a steering wheel
or pedals.
Here’s what would happen:
Without Problem
OS
No You’d only see a black screen or a blinking cursor
interface
Can’t run You wouldn’t be able to open Chrome, games, or
apps anything
No file You couldn’t store or retrieve documents, images,
system videos
Manual You’d have to write complex machine code to do
control anything, even just display “Hello”
No Anyone or anything could control your device
security without restrictions
Result: Useless for normal people. Only engineers could operate
it by writing low-level code directly to the hardware — every
time they wanted to do something.
🧒 Analogy for Beginners:
Think of a computer as a house:
● 🧱 Hardware = The bricks, wires, and plumbing
● 🧍 User = You, living in the house
● 🧰 Applications = Washing machine, fridge, AC
● 🧠 Operating System = The housekeeper or manager — turns on
the appliances, opens doors, manages power, talks to
service providers, etc.
Without the manager (OS), everything is there, but nothing works
together.
Types of Operating System:
Batch
Multi-programmed
Multi-tasking
Real time OS
Distributed
Clustered
Embedded
🧠 Types of Operating Systems
1. 📦 Batch Operating System
👉 No user interaction; jobs are collected in a “batch” and
run together.
How it works:
● Users submit jobs (programs) on punch cards or scripts.
● OS executes them one by one automatically without stopping for
user input.
Real-Life Analogy:
Like sending a pile of clothes to laundry. You don’t wait and watch —
the machine does it all in a batch.
Example:
● Early mainframes (IBM computers in the 1950s/60s)
● Payroll systems
📝 Drawback: No real-time feedback.
2. 🧩 Multi-Programmed Operating System
👉 Multiple programs stay in memory and the CPU switches
between them.
How it works:
● OS picks a job and runs it.
● If that job needs I/O (like waiting for input), CPU is given to
another job.
● Maximizes CPU usage.
Real-Life Analogy:
A chef cooking 3 dishes at once. While one is boiling, he chops
veggies for another — no time is wasted.
Example:
● UNIX
● Linux
3. 🔄 Multi-Tasking Operating System
👉 Allows multiple tasks (programs) to run at the same time.
How it works:
● The CPU quickly switches between programs (called context
switching), giving the illusion of simultaneous execution.
Real-Life Analogy:
You’re watching YouTube, downloading a file, and typing in Word — all
at the same time!
Example:
● Windows 10, macOS, Android
4. ⏱️ Real-Time Operating System (RTOS)
👉 Gives instant response — used where timing is critical.
How it works:
● Responses are guaranteed within strict time limits.
● Used in embedded systems, medical machines, robots, military.
Real-Life Analogy:
Airbag in a car — must inflate within milliseconds after collision.
No delays allowed!
Types:
● Hard RTOS: No delay allowed (e.g., pacemaker)
● Soft RTOS: Minor delays okay (e.g., streaming audio)
Example:
● VxWorks, QNX, RTLinux
5. 🌍 Distributed Operating System
👉 Controls and coordinates multiple computers as if they are
one.
How it works:
● Many computers are connected via a network.
● They share tasks, data, and resources.
● User sees them as one single system.
Real-Life Analogy:
Like Google Search — you type once, but thousands of servers work
together behind the scenes to give you results fast.
Example:
● Amoeba, Plan 9
● Google's internal systems
● Hadoop clusters
6. 💻 Clustered Operating System
👉 A group of connected computers (cluster) work together for
high availability and performance.
How it works:
● Similar to distributed OS but mainly used for fault tolerance and
performance.
● If one system fails, another takes over.
Real-Life Analogy:
Like a team of doctors in surgery — if one gets tired or distracted,
another takes over instantly.
Example:
● Windows Server Failover Cluster
● Linux HA (High Availability) clusters
7. 📲 Embedded Operating System
👉 Built into specific devices, designed to do just one job.
How it works:
● Very small, lightweight, and fast.
● Does not allow user to install or modify apps.
Real-Life Analogy:
Your microwave oven or washing machine runs software inside it. You
can’t install games on it!
Examples:
● Smart TVs
● Car infotainment systems
● Fitbit (wearables)
● Embedded Linux, FreeRTOS
🔄 Quick Summary Table
Type Purpose Example Devices/Use
Batch OS Run jobs in groups (no Old payroll systems
interaction)
Multi-Programmed Keep CPU busy with multiple UNIX systems
jobs
Multi-Tasking Multiple apps for one user Windows, Android,
macOS
Real-Time OS Instant response, strict Medical devices, car
timing airbags
Distributed OS Many computers acting as one Google servers,
large apps
Clustered OS Reliable performance using Banking,
many systems supercomputing
Embedded OS Simple OS in smart devices TVs, watches,
printers
🔁 Multiprogrammed OS – Non-Preemptive
📌 What does Non-Preemptive mean?
🔸 Once a program starts using the CPU, it keeps using it
until it's done or waits for something (like input).
💡 Example:
Imagine a single-lane bridge. Only one car (program) can pass at a
time, and no one else can interrupt it halfway.
👩🍳 Kitchen Example:
You are baking a cake and won’t let anyone else use the oven until
you’re done. Others must wait.
📌 In a Multiprogrammed OS:
● Multiple programs are loaded in memory, but only one runs at a
time.
● If that program needs to wait (e.g. for a file), then the CPU is
given to another program.
● The CPU is never left idle, but doesn’t interrupt a running
program by force.
🧠 Think of it as: "I’ll only give someone else a turn after this
person is finished or takes a break."
🔄 Multitasking OS – Preemptive / Responsive
📌 What does Responsive mean?
🔸 The OS quickly switches between tasks to make it feel like
everything is running at the same time.
🕹️ Example:
You are chatting, listening to music, and downloading a file. All
seem to happen at once. That’s because the OS keeps switching quickly
between them — that’s responsiveness!
📌 In a Multitasking OS:
● OS can interrupt a program that’s using the CPU and switch to
another one.
● This switching happens very fast, so it feels like all apps are
running together.
● Called preemptive multitasking — the OS decides when to pause a
program and switch to another.
🧑🍳 Kitchen Example:
You are cooking 3 dishes. You:
● Boil pasta for 5 mins ⏱️
● Switch to stir-fry 🥦
● Then bake a pie 🥧
You keep switching between dishes — this is like the OS quickly
switching between programs to keep everything going.
🧠 What is a Process?
A process is a program that is currently being executed. For example,
when you open Google Chrome, that application becomes a process in
your operating system.
🔄 Process States
Imagine a person ordering pizza in a restaurant. Each stage of their
journey maps to how a process behaves inside an OS:
1. 🤟 New
● The process is just created.
● Not yet in memory (RAM).
● It hasn’t entered RAM yet.
● Analogy: You just entered the pizza shop.
2. ✅ Ready
● Loaded into RAM, waiting for CPU.
● The process is loaded in RAM, and waiting to get CPU time.
● Analogy: Waiting in line to place your order.
3. 🏃 Running
● Currently using the CPU.
● The process is being executed by the CPU.
● Analogy: The chef is now making your pizza.
4. 🛌 Blocked/Waiting
● Waiting for I/O (e.g., reading from a file).
● The process is waiting for some input/output (I/O) operation like
reading from a file or waiting for disk input.
● Analogy: The chef is waiting for cheese delivery.
5. ✅ Ready Again
● After I/O, the process returns to Ready state.
● After I/O is done, the process goes back to Ready state to wait
again for the CPU.
● Analogy: Cheese arrives, and your pizza-making resumes.
6. ❌ Terminated
● Process is completed.
● Analogy: You got your pizza and left.
Additional States:
Ready Suspend
● Ready process moved from RAM to disk due to memory shortage.
● A ready process is moved from RAM to disk temporarily.
● Happens when RAM is full.
● Analogy: Asked to wait outside because the restaurant is full.
Blocked Suspend
● Blocked process also moved to disk.
● A process is blocked and also swapped out to disk due to memory
shortage.
● Analogy: WYou're waiting for cheese, but also sent outside.
VIP Process
● High-priority processes (like system processes) can interrupt
others.
● Some processes are more important (like security or system
processes).
● The OS may interrupt others to run them.
📊 Scheduling & Types of Schedulers
🧭 1. Long-Term Scheduler
● Decides which processes enter the Ready queue from New.
● Controls the degree of multiprogramming (how many total processes
are in memory).
● Example: Decides whether to admit MS Word, Chrome, and Spotify
into RAM.
🕐 2. Short-Term Scheduler (CPU Scheduler)
● Chooses which Ready process goes to Running.
● Makes frequent decisions, often every few milliseconds.
📨 3. Medium-Term Scheduler
● Handles suspension.
● Swaps out less important processes when RAM is full.
● Brings them back when RAM has space.
1. 🔬 Long-Term Scheduler
● Decides which processes go from New to Ready.
● Controls how many processes are in memory.
2. ⏱ Short-Term Scheduler
● Picks which Ready process runs next.
● Runs frequently, usually every few milliseconds.
3. 📨 Medium-Term Scheduler
● Handles suspending and resuming processes (Ready Suspend and
Blocked Suspend).
⏲ Time Quantum (Round Robin)
A fixed amount of CPU time given to each process.
If the process doesn’t finish, it’s moved back to Ready queue.
A fixed amount of time each process gets with the CPU. If the time
expires and it's not done, it goes back to Ready.
● Analogy: Each customer gets 5 minutes with the chef. If not done,
they go back in line.
⚔️ Preemptive vs Non-Preemptive Scheduling
Feature Preemptive Non-Preemptive
Can be ✅ Yes ❌ No (runs until
interrupted? done or waits)
Fairness High Can lead to long
waits
Example Algo Round Robin, FCFS, SJF
Priority
🔧 CPU Types
🧠 Uniprocessor:
Only one CPU.
Only one process runs at a time.
● One CPU, one process runs at a time.
🤜🤛 Multiprocessor:
● Multiple CPUs.
● Multiple processes can run in parallel.
● Multiple CPUs (or cores).
● True parallel processing.
● Multiple processes can run at the same time on different CPUs.
💡 Example:
● 1 cook (CPU) → 1 pizza at a time.
● 4 cooks (CPUs) → 4 pizzas at the same time!
📀 I/O Operations & Block State
● If a process needs to read/write from disk (secondary memory), it
enters Blocked state.
● After I/O finishes, it goes back to Ready.
💾 I/O Operation & Secondary Memory
(Wait/Block State?)
When a process needs to read/write data from secondary memory (like
hard disk):
● It moves to Blocked/Waiting state.
● Why? Because I/O operations take time and CPU should not sit
idle.
So:
I/O = Process waits → Blocked state → After done → Back to
Ready.
📤 Deallocation
● When a process finishes, its resources (RAM, files, etc.) are
released.
🔝 Process Priority
● High-priority processes get CPU time sooner.
● Example: Antivirus > Background music player.
📶 How Many Processes Can Be in Running State?
● Depends on the number of CPUs:
○ 🧠 1 CPU = 1 process can run at a time.
○ 🧠🧠🧠 4 CPUs = 4 can run in parallel.
Others wait in Ready queue.
🔝 Priority of a Process
● OS gives importance (priority) to certain processes:
○ High: system update, antivirus
○ Medium: browser
○ Low: background music player
Preemptive systems can pause a low-priority process to run a
high-priority one.
💡 State Transition Flow
● Processes may be in one of 5 states, as shown in Figure 3.2
below.
○ New - The process is in the stage of being created.
○ Ready - The process has all the resources available that it
needs to run, but the CPU is not currently working on this
process's instructions.
○ Running - The CPU is working on this process's instructions.
○ Waiting - The process cannot run at the moment, because it
is waiting for some resource to become available or for some
event to occur. For example the process may be waiting for
keyboard input, disk access request, inter-process messages,
a timer to go off, or a child process to finish.
○ Terminated - The process has completed.
● The load average reported by the "w" command indicate the average
number of processes in the "Ready" state over the last 1, 5, and
15 minutes, i.e. processes who have everything they need to run
but cannot because the CPU is busy doing something else.
● Some systems may have other states besides the ones listed here.
Suspend transitions happen when memory is low.
Important LINUX command
🛡️ What are User, Group, and Others in Linux?
Every file/folder in Linux has permissions that control who can do
what with it.
Linux divides users into three categories:
Category Who they are Example
User (u) The owner of the file (you) You, the creator of the
file
Group (g) A group of users with shared Your teammates
access
Others (o) Everyone else on the system Outsiders or guests
🔑 What are Permissions?
There are three basic permissions:
Symbol Name Meaning
r read Can view the content
w write Can modify or delete
x execute Can run the file (like a program or script)
🎯 Interpretation:
● User (owner) can read, write, and execute
● Group can read only
● Others can read only
🛠️ Changing Permissions with chmod
You can use chmod to change permissions:
🔢 Numeric Method (Easy to Remember):
Permission Value
read (r) 4
write (w) 2
execute (x) 1
Then add them together:
● 7 = 4+2+1 → read + write + execute
● 6 = 4+2 → read + write
● 5 = 4+1 → read + execute
● 4 = 4 → read only
💡 Example:
Means:
● User: read, write, execute ✅
● Group: read, write, execute ✅
● Others: ❌ no access at all
🧩 Part 1: Understanding File Permissions
with chmod
❓Q: Which command is used to assign only read permission
to all three categories of file 'note'?
👉 We're trying to make the file read-only for:
● User (u)
● Group (g)
● Others (o)
✅ Correct Answer: chmod ugo=r note
🔍 Why?
● chmod changes file permissions.
● ugo=r means:
○ User gets only read (r)
○ Group gets only read (r)
○ Others get only read (r)
● This gives permission like:
Equivalent Octal Notation: chmod 444 note
Each r-- = 4 (read = 4, write = 2, execute = 1)
So: user = 4, group = 4, others = 4 → chmod 444
🧩 Part 2: Octal Permission Notation
❓Q: chmod ugo+rw note command can be represented in
octal as?
👉 ugo+rw means:
● Everyone gets read and write, but no execute.
🔢 Breakdown:
Category r w x Total
User 1 1 0 6
Group 1 1 0 6
Others 1 1 0 6
✅ Correct answer: chmod 666 note
Octal Code :
Permission Binary Octal
rwx 111 7
rw- 110 6
r-x 101 5
r-- 100 4
-wx 011 3
-w- 010 2
--x 001 1
--- 000 0
🧩 Part 3: Understanding lseek() and File
Descriptors
❓Q: What will be the current position of R/W head after
two lseek calls?
We are told:
● File content:
Two commands:
💡 Let's break it step by step:
1️⃣ lseek(n, 10, SEEK_CUR)
● SEEK_CUR = move relative to current position
● Assuming we're at position 0 initially → move to position 10
2️⃣ lseek(n, 5, SEEK_SET)
● SEEK_SET = move to absolute position 5 (from start)
✅ Final position = 5 ,✔️ Correct answer: (B) 5
Concept Meaning
chmod ugo=r file Set read-only permission for
everyone
chmod 444 file Same as above in octal
chmod ugo+rw file Give read + write to all
chmod 666 file Same as above in octal
lseek(fd, offset, SEEK_CUR) Move pointer relative to current
position
lseek(fd, offset, SEEK_SET) Move pointer to absolute position
Think of your computer as a house
● 🧍♀️ You (the user) can walk around the living room, kitchen, etc.
● 🚪But some areas, like the electrical fuse box, are restricted —
only a qualified technician (like an electrician) should touch
it.
This is how User Mode and Kernel Mode work in an operating system.
🧍♀️ What is User Mode?
👉 It's where normal applications and users run.
🧠 Examples:
● Your browser (like Chrome)
● A game you're playing
● A music player
🛡️ Limitations:
● Cannot directly access hardware like RAM, CPU, or disk
● Cannot modify system-level settings
● Needs permission to talk to hardware
📦 Why?
To protect the system. We don’t want a buggy app to crash the entire
computer or corrupt files.
👑 What is Kernel Mode?
👉 It’s the heart of the operating system — like the technician
working behind the scenes.
💻 It has full control of:
● CPU
● Memory (RAM)
● Hard Disk
● Device Drivers
● Security
🛠️ Used by:
● The Operating System (like Linux, Windows)
● Low-level system functions
● Drivers
🚨 If something goes wrong in kernel mode, it can crash the entire
system (called a kernel panic).
🧱 How They Work Together (User Mode →
Kernel Mode)
When an app wants to do something sensitive, like saving a file to
disk, it can't do it directly.
✅ It must ask the OS for help.
📞 Example:
This is done via a System Call — a special request from user mode
to kernel mode.
⚖️ Why is this separation important?
✅ Security:
Prevents malware or buggy programs from damaging the system.
✅ Stability:
One bad program won’t crash the entire OS.
✅ Control:
Only the OS decides what apps are allowed to do.
🧠 User Mode = Mode Bit 1
👑 Kernel Mode = Mode Bit 0
These are internal bits used by the CPU to decide whether the system
is running in user mode or kernel mode.
🎯 What does it mean?
🧍♀️ User Mode → Mode Bit = 1
● When a regular user program is running (like a browser or text
editor),
the mode bit is set to 1.
● This restricts access to hardware.
● If the program tries to access protected memory or hardware
directly → it gets an error.
✅ Safe zone
✅ Cannot harm system directly
✅ Needs permission (via system calls) to interact with hardware
👑 Kernel Mode → Mode Bit = 0
● When the operating system (kernel) is running,
the mode bit is 0.
● It has full control of the system:
○ Can access RAM, CPU, disk
○ Manage files, devices, networking, security
🚨 Dangerous if buggy
⚙️ Used for low-level operations
🔄 Switches from user to kernel mode during system calls
🔁 Switching Between Modes (How it works):
1.Program runs in user mode (mode bit = 1)
2.It wants to access a file → can't do it directly
3.Makes a system call → switches to kernel mode (mode bit = 0)
4.Kernel performs the action (e.g., read/write)
5.Then switches back to user mode
What is a System Call?
Imagine you’re using a mobile app and you click “Save.” The app can't
directly write to disk — it needs to ask the OS to do that.
That request is called a System Call.
🧩 Why System Calls?
👉 User Mode programs (like your code, browser, or app) can’t access
hardware directly
👉 So they ask the Kernel (the boss of the OS) to do tasks using
system calls
📚 Types of System Calls
Let’s break down each category from the image:
1️⃣ File Related System Calls
Used when working with files
🛠️ Examples:
● open() → Open a file
● read() → Read data from a file
● write() → Write data to a file
● close() → Close an open file
● create() → Create a new file
Example:
Like opening, reading, writing in a notebook — but asking the OS to
do it.
2️⃣ Device Related System Calls
Used to interact with hardware devices (like keyboards, USB, mouse)
🛠️ Examples:
● read() / write() → Talk to device (like reading input from
keyboard)
● reposition() → Change read/write position (like moving cursor in
a file)
● ioctl, fcntl → Advanced device control (like changing screen
brightness)
Example:
Like asking the OS: “Hey, give me data from the printer” or “Move
mouse cursor here.”
3️⃣ Information Related System Calls
Used to get info about processes or system
🛠️ Examples:
● getpid() → Get the Process ID
● attributes → Get process or file info
● get time/date → What’s the current time?
Example:
Asking “What is my process number?” or “What time is it?”
4️⃣ Process Control System Calls
Used to manage running programs
🛠️ Examples:
● load() → Load a program into memory
● execute() → Run a program
● abort() → Stop a program
● fork() → Create a new process
● wait() → Wait for another process to finish
● signal() → Send signals between processes
Example:
Think of launching or killing apps on your phone — the OS does that
via these system calls.
5️⃣ Communication System Calls
Used to let processes talk to each other (IPC = Inter-Process
Communication)
🛠️ Examples:
● pipe() → Connect two programs (like one sends, one receives)
● shmget() → Shared memory (like common notepad for two apps)
● create/delete connection → For network or inter-process links
Example:
Like two people passing messages through a pipe.