Operating System
Operating System
Definition:
The processor is the brain of the computer, executing instructions and managing tasks.
Key Components:
Types:
Key Specs:
2. Memory
Definition:
Memory stores data temporarily or permanently for CPU access.
Types of Memory:
3. Devices
Input Devices:
Output Devices:
Storage Devices:
Definition:
A communication pathway that transfers data between the CPU and peripheral devices.
Types of Buses:
Q System Calls
System Calls:
1. Requests services from the operating system kernel.
2. Provides interface between user programs and OS.
Types of System Calls:
1. Process Control: Create, terminate, and manage processes.
2. File Management: Create, read, write, and delete files.
3. Device Management: Request access to hardware devices.
4. Information: Get system information, process status.
5. Protection and Security: Set permissions, access control.
Examples:
1. fork() (create new process)
2. open() (open file)
3. read() (read from file)
4. write() (write to file)
5. exit() (terminate process)
Benefits:
1. Standardized interface
2. Hardware abstraction
3. Security and access control
Q Types of schedulers
Types of Schedulers:
1. Long-Term Scheduler (Job Scheduler):
- Decides which processes to admit to the system.
- Determines degree of multiprogramming.
2. Short-Term Scheduler (CPU Scheduler):
- Allocates CPU to processes.
- Makes decisions on which process to run next.
3. Medium-Term Scheduler (Swapper):
- Manages memory by swapping processes in and out.
- Helps with memory management and multitasking.
Each type of scheduler plays a crucial role in managing system
resources and process execution.
Methods:
1. Message Passing: Processes exchange messages.
2. Shared Memory: Processes share a common memory space.
3. Pipes: Unidirectional communication channel.
4. Sockets: Network-based communication.
5. Semaphores: Synchronization mechanism
Q Race Condition
Q Critical region
Q use of Semaphore
✅ What is a Semaphore?
Q monitor
an electronic device with a screen used for display (as of television pictures or
computer information)
1. Producer-Consumer Problem
A producer puts items into a buffer, and a consumer takes them out.
They must not use the buffer at the same time or overflow/underflow
it.
2. Reader-Writer Problem
Multiple readers can read shared data at the same time, but a writer
must have exclusive access. The goal is to prevent conflicts between
reading and writing.
Philosophers sit at a table with one fork between each of them. Each
needs two forks to eat. The problem is to avoid deadlock and ensure
everyone gets a turn.
4. Sleeping Barber Problem
Q Deadlock
Deadlock is a situation in computing where two or more
processes are unable to proceed because each is waiting for the
other to release a resource. This typically happens in multitasking
or multiprocessing environments where processes compete for
limited resources (like memory, files, or printers).
Q Deadlock Characterization
Deadlock Characterization:
Necessary Conditions:
1. Mutual Exclusion: Resources are non-shareable.
2. Hold and Wait: Processes hold resources while waiting for others.
3. No Preemption: Resources cannot be forcibly taken away.
4. Circular Wait: Processes wait for each other in a circular chain.
Deadlock Implications:
1. System deadlock: Entire system comes to a halt.
2. Resource waste: Resources are held but not used.
Handling Deadlocks:
1. Prevention: Prevent one of the necessary conditions.
2. Avoidance: Use algorithms to avoid deadlocks (e.g., Banker's
algorithm).
3. Detection: Detect deadlocks and recover.
4. Recovery: Abort processes or preempt resources.
1. Deadlock Prevention
2. Deadlock Avoidance
Goal: Avoid entering unsafe states that might lead to deadlock.
How: System uses algorithms (e.g., Banker’s Algorithm) to
check whether resource allocation will keep the system in a safe
state.
✅ Pros: Allows better resource use than prevention.
❌ Cons: Requires advance knowledge of future requests; not
scalable for large systems.
Goal: Do nothing.
How: Simply assume that deadlocks are rare and ignore them.
✅ Pros: Simplifies OS design.
❌ Cons: Risk of indefinite freezing or system failure.
🚨 Used in UNIX, Linux, and other general-purpose operating
systems.
Q Deadlock prevention and avoidance
1. Deadlock Prevention
2. Deadlock Avoidance
Q Paging
Paging is a function of memory management where a computer will
store and retrieve data from a device's secondary storage to the
primary storage
Q Swapping.
Q Virtual memory:
Virtual memory is a memory management technique that allows
a computer to use secondary storage (like a hard drive or SSD)
as if it were part of the RAM, creating the illusion of a larger
memory space.
Q paging
When a program needs a page that’s not in memory, and the RAM is
already full, the system must remove a page to make space. This is
called page replacement.
Q page Size
Q Segmentation
Instead of dividing memory into fixed-size pages, segmentation
divides a program’s memory into logical parts called segments.
Q File management:
File Management is how an operating system (OS) organizes,
stores, and retrieves data on storage devices like hard drives, SSDs,
or USB drives
Q File naming
File naming is how we give a name to a file so it can be identified
and accessed by the operating system and users
Q File structures
File structure refers to how data is organized inside a file. Just like
books can have chapters or sections, files can be organized in
different ways depending on how the data will be used.
Q file types
File types tell us what kind of data a file contains and which
program can open it.
Each file type has a specific file extension, like .txt, .jpg, or .mp3.
Q Single Level and Hierarchical OS
Q Shared file
We need to control who can use what, to keep things safe and
organized.
This is where protection comes in — the operating system decides
what each user or program is allowed to do.
🧑 1. Protection Domain
It defines what a user or program can access and what actions they
can perform.
What happens?
A program tries to put more data into a memory space (buffer)
than it can hold.
Why is it bad?
The extra data can overwrite nearby memory, causing crashes
or letting attackers run harmful code.
Simple example:
Imagine a cup that holds 10 ounces of water, but you pour 15
ounces — the extra spills over and makes a mess.
What happens?
When a number gets too big for the space reserved (like a small
container), it wraps around to a small or negative number.
Why is it bad?
This can trick the program into thinking a calculation is safe
when it’s not, causing bugs or security holes.
Simple example:
Imagine a clock that goes up to 12, but if you add 1 after 12, it
resets to 1. If your program doesn’t expect this, it can cause
errors.
⚠️ 3. Dangling Pointer
What happens?
A pointer (a variable that holds a memory address) points to
memory that has already been freed or deleted.
Why is it bad?
Using a dangling pointer can crash the program or cause
unpredictable behavior.
Simple example:
It’s like having a map to a house, but the house has been torn
down — trying to go there leads nowhere or danger.
What happens?
The program tries to use a pointer that points to nothing (null).
Why is it bad?
Accessing null memory causes the program to crash (crash or
denial of service).
Simple example:
It’s like trying to open a door that doesn’t exist — you can’t
enter and might hurt yourself.
🧑 What is Malware?
What it is:
A virus is a program that attaches itself to other programs or
files and spreads when those files run.
How it spreads:
When you run an infected program or open an infected file, the
virus activates and tries to infect other files.
What it does:
Can delete files, slow down your computer, or cause crashes.
Analogy:
Like a cold virus that spreads when people shake hands.
2. 🐌 Worm
What it is:
A worm is a standalone program that can copy itself and
spread independently over networks.
How it spreads:
Without needing to attach to other programs, worms move from
computer to computer on the internet or local networks.
What it does:
Can clog networks, slow down systems, or install backdoors.
Analogy:
Like a worm that moves through soil by itself, infecting
everything it touches.
1. Transparency
Make the whole system look like one single computer to
users and programs, hiding the complexity of multiple
machines.
Types of transparency:
o Access transparency: Users access resources
Q Clock Synchronization