0% found this document useful (0 votes)
5 views14 pages

OS Module1 Notes and Solutions

The document provides an overview of operating systems, covering their definition, functions, services, types, and structures. It details the boot process, multitasking techniques, system calls, and examples of operating systems like Linux and Windows. Additionally, it includes solved exam questions related to OS concepts and scenarios.

Uploaded by

48.adityanare
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views14 pages

OS Module1 Notes and Solutions

The document provides an overview of operating systems, covering their definition, functions, services, types, and structures. It details the boot process, multitasking techniques, system calls, and examples of operating systems like Linux and Windows. Additionally, it includes solved exam questions related to OS concepts and scenarios.

Uploaded by

48.adityanare
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MODULE 1 — REVISION NOTES

Fundamentals of Operating Systems


OS Overview · Boot Process · Functions · Services · Types · Structures · System Calls

1. What is an Operating System?


An OS is an intermediary between the user and hardware. It provides an environment to execute programs
conveniently and efficiently, managing all hardware resources.

Layer Description
Users People using the computer
Application Programs Browsers, games, databases, video players
System Programs Shells, editors, compilers
Operating System Interface between user and hardware (special program)
Hardware CPU, Memory, Disks, I/O devices

Primary Goals of OS
1. Convenience — Makes computer use easy, no manual configuration 2. Efficiency — Ensures
resources are used optimally 3. Ability to Evolve — New features can be added without disrupting
service 4. Resource Management — Fair sharing of resources among processes and users

2. System Boot Process


Booting = the process of loading the OS from secondary storage (HDD/SSD) into RAM when the computer is
powered on. The OS must be in RAM to manage hardware and software.

2.1 Types of Booting


Type Description
Cold / Hard Boot Computer powered ON from fully off state. Full POST runs,
hardware initialized, OS loaded from scratch. Example: pressing
power button.
Warm / Soft Boot Restart without full shutdown. Skips some hardware checks —
faster. Example: Start → Restart, or Ctrl+Alt+Del.

2.2 Steps in the Boot Process


1. Power On — Electricity flows to motherboard and CPU.
2. BIOS/UEFI Execution — Firmware loads and runs POST (Power-On Self Test) to check hardware.
3. Boot Device Selection — BIOS searches for bootable device based on configured boot order.
4. Loading Bootloader — BIOS reads Master Boot Record (MBR) or EFI partition and loads the bootloader.
5. Loading the OS — Bootloader loads the OS kernel into main memory (RAM).
6. System Configuration — OS initializes device drivers and system utilities.
7. User Login — System presents login screen for user authentication.

2.3 Dual Booting


When two or more OS are installed on the same computer. A boot loader recognizes different file systems. Each
OS is stored on a different partition. At startup, a boot manager shows a menu to select which OS to load.

3. Functions of Operating System


Function Details
1. Memory Allocates/deallocates RAM. Tracks which memory is used by whom. Handles
Management multiprogramming memory distribution.
2. Processor Schedules processes to CPU. Tracks process status. Allocates/de-allocates
Management CPU time. Uses algorithms: FCFS, SJF, Round Robin.
3. Device Tracks all connected devices. Manages I/O controller programs.
Management Allocates/deallocates devices as needed.
4. File Management Tracks file status and location. Allocates/deallocates file resources. Decides
who gets file access and for how long.
5. Storage Optimizes use of storage devices. Handles file/directory creation, reading,
Management writing, copying. Prevents data loss.
6. Security Password protection. Firewall management. Prevents unauthorized access.
Displays vulnerability messages.

4. Operating System Services


• User Interface (UI) — CLI (text commands), GUI (graphical), Batch interface
• Program Execution — Loads and runs user/system programs
• I/O Operations — Handles keyboard, mouse, display, disk I/O
• File System Manipulation — Create, delete, read, write, open, close files
• Resource Allocation — Decides who gets CPU, memory, devices and for how long
• Accounting — Tracks system usage, errors, resource consumption
• Information & Resource Protection — Prevents unauthorized access
• Communication — IPC between processes on same or different machines
• Error Detection — Detects and corrects CPU, memory, I/O, and program errors

5. Types of Operating Systems


Type Description Examples
Batch OS Groups similar jobs into batches. No direct Payroll systems, bank
interaction with CPU. statements
Time-Shared OS Multiple users/tasks share CPU time UNIX
(quantum). Also called multitasking.
Distributed OS Multiple CPUs, no shared memory. OS LOCUS
distributes tasks. Communicates via
network.
Network OS Connected systems share resources via Windows Server, Linux
server (files, printers, apps).
Real-Time OS Extremely fast response time. Hard RTOS Missile systems, robots, QNX
(RTOS) (strict deadline) vs Soft RTOS (flexible).

6. Operating System Structures


6.1 Layered Structure
OS broken into layers. Layer 0 = hardware (bottom), Layer N = user interface (top). Each layer uses only services
of the layer below it.
• Layers: Hardware → CPU Scheduling → Memory Management → Process Management → I/O Buffer →
User Programs
• Advantage: Modular, easy to debug and update, abstraction, no direct hardware access
• Disadvantage: Slower (requests travel through all layers), complex implementation, no non-adjacent
communication

6.2 Monolithic Kernel


All OS components (memory, process, file, device management) in one large kernel in a single address space.
• Advantage: Very fast execution — all services in same address space
• Disadvantage: Entire system crashes if one service fails. Hard to extend.
• Examples: Linux, FreeBSD, Windows 95/98
6.3 Microkernel
Only essential services (IPC, memory, CPU scheduling) in kernel. Everything else runs in user space.
• Advantage: More stable (service crash doesn't crash system), more secure, easily extendible
• Disadvantage: Slower execution due to user-kernel space communication overhead
• Examples: QNX, Symbian, Mac OS X (Mach), L4 Linux

Feature Monolithic Kernel Microkernel


Address Space User + Kernel in SAME space User + Kernel in SEPARATE spaces
Size Larger Smaller
Speed Fast execution Slower execution
Stability One crash = whole system fails One crash = only that service fails
Extendibility Difficult to extend Easy to extend
Examples Linux, Windows 95 QNX, Symbian, macOS

7. System Calls
A system call is an interface that user programs use to request services from the OS kernel. It provides
controlled access to hardware.

Type Services Provided


1. Process Control Create/terminate processes, load/execute, wait for event, allocate/free
memory
2. File Management Create/delete files, open/close files, read/write files, get/set file attributes
3. Device Request/release devices, read/write/reposition devices, get/set device
Management attributes
4. Information Get/set time & date, get system/process/file info
Maintenance
5. Communication Create/delete connections, send/receive messages, attach/detach remote
devices
8. Shell & Linux Kernel
Shell
A command interpreter in OS (Linux/Unix). Acts as interface between user and OS. Sends commands to kernel
and returns output. Also a programming language (loops, functions, variables).
• Graphical Shell (GUI) — Windows, Ubuntu desktop environment
• Command-Line Shell (CLI) — Terminal (Linux/Mac), Command Prompt (Windows)
• Shell types: Bash, Csh/Tcsh, Ksh, Zsh, Fish

Linux Kernel
Created by Linus Torvalds as a hobby project. Open-source, monolithic kernel. Acts as bridge between user
applications and hardware. Manages all functions: process scheduling, memory, device drivers.
SOLVED EXAM QUESTIONS
OS Module 1 Theory Questions with Detailed Answers

Q1. Graphic Designer — Photoshop + Browser + File Sync [3 Marks]


Scenario:
A graphic designer runs Photoshop, a web browser playing music, and a file syncing service
simultaneously on a single-core CPU. Despite CPU executing one instruction at a time, all appear to
run simultaneously.

I. OS Technique Being Used

Answer
The technique being used is MULTITASKING / TIME-SHARING (also called CPU Multiplexing or
Multiprogramming with time-slicing). More specifically: Preemptive Multitasking — the OS
forcefully switches the CPU between processes at regular time intervals (time quantum).

II. How the OS Creates the Illusion of Simultaneity


Even though a single-core CPU can only execute one instruction at a time, the OS creates the illusion of
simultaneous execution through the following mechanism:

8. Time Slicing — The OS divides CPU time into very small intervals called time quanta (typically 10–100
milliseconds). Each process (Photoshop, browser, file sync) gets a turn.
9. Context Switching — When a process's time quantum expires, the OS saves its complete state (registers,
program counter, memory state) into its Process Control Block (PCB). The next process's state is then
restored and it resumes execution.
10. Process Scheduling — The OS Scheduler uses algorithms (like Round Robin) to decide which process runs
next and for how long, ensuring fairness.
11. Speed of Switching — The switching happens so rapidly (thousands of times per second) that it appears
simultaneous to the human user. The designer experiences no lag.
12. I/O Overlap — When Photoshop waits for disk I/O, the CPU is given to the browser or file sync,
maximizing CPU utilization.

Key Point
Photoshop (editing) → gets CPU for quantum → PAUSE (state saved) Browser (music) → gets CPU
for quantum → PAUSE (state saved) File Sync (upload) → gets CPU for quantum → PAUSE (state
saved) → Back to Photoshop ... (cycle repeats thousands of times/second) This rapid cycling creates
the ILLUSION of parallel execution.
Q2. File Download + Progress Bar + Cancel Button [3 Marks]
Scenario:
A developer's program downloads files while simultaneously showing a progress bar and allowing
cancellation — all within the same program, despite sequential CPU execution.

I. OS Concept Used

Answer
The concept used is MULTITHREADING — Multiple threads within the SAME process/program
running concurrently. Unlike multitasking (multiple processes), multithreading manages multiple
tasks WITHIN a single program.

II. How the OS Manages Activities Within the Same Program


A process (the download program) is divided into multiple threads, each handling a different task:

Thread Responsibility
Thread 1 — Downloader Handles actual file downloading from internet, manages network
I/O
Thread 2 — Progress Bar Reads download progress data and updates the UI bar in real-time
Thread 3 — Input Listener Monitors for the Cancel button click event from the user

13. Shared Memory — All threads share the same process memory space. Thread 2 reads the same
download counter that Thread 1 writes — no data copying needed.
14. Thread Scheduling — The OS schedules threads just like processes. Each thread gets CPU time slices,
creating the appearance of simultaneous operation.
15. Thread Communication — Threads communicate via shared variables. When Thread 3 detects a cancel
click, it sets a shared flag variable that Thread 1 reads and stops downloading.
16. Non-blocking I/O — While Thread 1 waits for network data (I/O block), CPU is freed for Threads 2 and 3,
keeping the UI responsive.
17. Lightweight Switching — Thread context switches are faster than process switches since threads share
the same address space — no memory mapping needed.

Thread vs Process
Threads: Share memory, faster to create/switch, communicate easily via shared variables Processes:
Separate memory, slower to switch, communicate via IPC (pipes, sockets) In this scenario: THREADS
are used because all 3 activities are part of ONE program and need to share download progress
data.
Q3. Boot Errors — Windows BOOTMGR & Linux GRUB Rescue [3 Marks]
Scenario:
Windows shows 'BOOTMGR is missing' during startup. Linux system stops at 'grub rescue>' prompt.

I. Boot Stage Where Failure Occurs


System Failure Stage & Reason
Windows — 'BOOTMGR is Failure occurs at Stage 4: Loading the Bootloader. BIOS found the
missing' disk/MBR but cannot load or locate the Windows Boot Manager
(BOOTMGR) file stored on the active partition. The MBR points to
BOOTMGR but the file is corrupted, missing, or the partition is
marked inactive.
Linux — 'grub rescue>' Failure occurs at Stage 4–5 boundary: GRUB was partially loaded
(Stage 1 of GRUB ran successfully) but GRUB Stage 2 failed —
meaning GRUB cannot find its configuration files ([Link]) or its
modules needed to load the OS kernel.

II. Complete Boot Process — Windows and Linux


Windows Boot Process:
18. Power On — Hardware powers up, CPU resets.
19. POST (Power-On Self Test) — BIOS/UEFI tests RAM, CPU, storage devices for faults.
20. BIOS/UEFI Loads — Firmware initializes, checks hardware inventory.
21. Boot Device Selection — BIOS reads configured boot order (HDD, USB, DVD).
22. MBR / EFI Partition Read — BIOS reads Master Boot Record (legacy) or EFI System Partition (UEFI). MBR
contains pointer to Windows Boot Manager.
23. BOOTMGR Loads — Windows Boot Manager (bootmgr) is loaded from the active partition. It reads BCD
(Boot Configuration Data) store.
24. [Link] — Boot Manager hands off to [Link] which loads the Windows kernel ([Link])
and HAL (Hardware Abstraction Layer).
25. Kernel Initialization — Windows kernel loads, initializes drivers, starts Session Manager ([Link]).
26. Windows Logon — [Link] starts, presents login screen.

Linux Boot Process:


27. Power On — Hardware powers up.
28. POST — BIOS/UEFI performs hardware self-test.
29. BIOS/UEFI — Firmware initializes, selects boot device.
30. MBR / EFI Partition Read — First 446 bytes of MBR contain GRUB Stage 1 bootloader code.
31. GRUB Stage 1 → Stage 1.5 — MBR code loads GRUB Stage 1.5 from sectors just after MBR (enough code
to understand filesystems).
32. GRUB Stage 2 — GRUB fully loads from /boot/grub/. Reads [Link] configuration. Displays boot menu.
33. Kernel Loading — GRUB loads the Linux kernel image (vmlinuz) and initramfs (initial RAM filesystem)
into memory.
34. Kernel Initialization — Kernel decompresses, initializes hardware, mounts root filesystem.
35. init / systemd — First process (PID 1) starts — either init or systemd. Starts all system services.
36. Login Screen — Display Manager (GDM, LightDM) or CLI login prompt appears.

III. Recovery Measures


System Recovery Steps
Windows — BOOTMGR 1. Boot from Windows Installation Media (USB/DVD) 2. Select
Missing 'Repair your computer' → Startup Repair 3. OR: Command Prompt
→ run: bootrec /fixmbr, bootrec /fixboot, bootrec /rebuildbcd 4.
Check if active partition is set correctly using diskpart → list
partition → select partition → active 5. If BCD corrupt: bcdedit
/export C:\BCD_Backup, then rebuild
Linux — GRUB Rescue 1. At grub rescue prompt: ls to list drives and partitions 2. Find
correct partition: ls (hd0,msdos1)/boot/grub to check 3. Set prefix
and root: set root=(hd0,1), set prefix=(hd0,1)/boot/grub 4. Load
normal module: insmod normal, then normal 5. Once booted: run
sudo update-grub and sudo grub-install /dev/sda to fix permanently
6. Alternative: Boot from Live USB → chroot into system → reinstall
GRUB

Q4. C Program — File, Child Process, Communication [3 Marks]


Scenario:
A C program opens a file, reads data, creates a child process, and communicates with it. Identify
system calls, classify them, and explain why system calls are necessary.

I. Types of System Calls Involved

System calls involved:


File Operations: open(), read(), close() Process Control: fork(), exec(), wait(), exit() Communication:
pipe(), write(), read() on pipe Memory (implicit): malloc() triggers brk()/mmap() Information:
getpid(), getppid()

II. Classification of System Calls


Category System Calls What it does in this program
Process Control fork(), exec(), fork() creates child process. exec() loads
wait(), exit() new program into child. wait() makes
parent wait for child. exit() terminates
process.
File Management open(), read(), open() opens the file. read() reads data
write(), close() from file. write() writes output. close()
releases the file descriptor.
Communication pipe(), read(), pipe() creates a communication channel
write() between parent and child process.
read()/write() on pipe transfer data
between them.
Information Maintenance getpid(), getppid() Retrieves process IDs — parent uses
these to track child process.

III. Why System Calls Are Necessary Instead of Direct Hardware Access
37. Protection & Security — Hardware is a shared resource. If any program could directly access hardware
(disk, memory, CPU registers), one malicious or buggy program could corrupt data of other programs or
the entire system. System calls provide a controlled gateway.
38. Kernel Mode vs User Mode — Programs run in User Mode (restricted). Hardware access requires Kernel
Mode (privileged). System calls are the ONLY legitimate way to switch from User Mode to Kernel Mode
safely via a software interrupt (INT 0x80 or syscall instruction).
39. Abstraction — Programs don't need to know specific hardware details. open('/home/[Link]') works
regardless of whether it's on HDD, SSD, or network storage. The OS handles the hardware-specific
details.
40. Resource Management — The OS allocates resources fairly. If a program directly accessed the disk, it
could lock other programs out. System calls allow the OS to schedule, queue, and manage all hardware
requests.
41. Portability — Programs using system calls work across different hardware. The OS provides a uniform
API. Without system calls, every program would need to know specific hardware addresses and
protocols — making programs hardware-dependent.

Simple Analogy
Think of system calls like a hotel concierge service: • You (user program) cannot go into the kitchen
(hardware) directly • You must ask the concierge (OS via system call) to bring food (hardware
service) • The concierge ensures fair service, security, and proper resource use
Q5. Print Server — Semaphore Solution [7 Marks]
Scenario:
A print server maintains a fixed-size print queue. Multiple student computers (producers) submit
print jobs. A single printer (consumer) processes jobs one at a time. • If queue is FULL → student
computers must WAIT (cannot add) • If queue is EMPTY → printer must WAIT (cannot process)
Apply SEMAPHORE concept to solve this Producer-Consumer problem.

Problem Identification
This is the classic Producer-Consumer Problem (also called Bounded Buffer Problem). It requires synchronization
between multiple producers (student computers) and one consumer (printer) using semaphores.

Element Description
Shared Resource Print Queue (fixed-size buffer of size N)
Producers Student computers — submit/add print jobs to queue
Consumer Printer — removes and processes jobs from queue
Problem 1 — Full Queue If queue full, producer must WAIT until space is available
Problem 2 — Empty Queue If queue empty, consumer must WAIT until job is available
Problem 3 — Race Condition Multiple producers writing simultaneously can corrupt queue —
need MUTUAL EXCLUSION

Semaphore Definitions

Three Semaphores Required:


1. empty — Counting Semaphore Initialized to N (queue capacity) Tracks number of EMPTY slots
available in the queue Producer waits on this if queue is full 2. full — Counting Semaphore
Initialized to 0 Tracks number of FILLED slots (jobs waiting) in the queue Consumer waits on this
if queue is empty 3. mutex — Binary Semaphore (1 or 0) Initialized to 1 Ensures MUTUAL
EXCLUSION — only ONE process accesses queue at a time Prevents race conditions when multiple
producers add jobs simultaneously

Semaphore Operations (P & V)


Operation Meaning
wait(S) / P(S) / down(S) Decrements semaphore S by 1. If S becomes negative → process
BLOCKS (waits). Used BEFORE entering critical section or accessing
resource.
signal(S) / V(S) / up(S) Increments semaphore S by 1. If processes waiting → WAKES one
up. Used AFTER leaving critical section or releasing resource.
Complete Algorithm / Pseudocode
Initialization:

semaphore empty = N; // N = queue capacity (total empty slots)


semaphore full = 0; // Initially 0 jobs in queue
semaphore mutex = 1; // Binary semaphore for mutual exclusion
int queue[N]; // Shared print queue (circular buffer)
int in = 0; // Producer insertion pointer
int out = 0; // Consumer removal pointer

PRODUCER (Student Computer — submitting a print job):

Producer() {
while (true) {
print_job = create_print_job(); // Prepare the print job

wait(empty); // P(empty): Decrement empty count


// If empty == 0 (queue full), BLOCK here and
wait

wait(mutex); // P(mutex): Enter critical section


// Ensure only ONE producer adds at a time

queue[in] = print_job; // Add job to queue


in = (in + 1) % N; // Move insertion pointer (circular)

signal(mutex); // V(mutex): Exit critical section


signal(full); // V(full): Increment full count
// Wakes up printer if it was waiting
}
}

CONSUMER (Printer — processing a print job):

Consumer() {
while (true) {
wait(full); // P(full): Decrement full count
// If full == 0 (queue empty), BLOCK here and
wait

wait(mutex); // P(mutex): Enter critical section


// Mutual exclusion while accessing queue

print_job = queue[out]; // Remove job from queue


out = (out + 1) % N; // Move removal pointer (circular)

signal(mutex); // V(mutex): Exit critical section


signal(empty); // V(empty): Increment empty count
// Wakes up waiting producer if queue was full

process_print_job(print_job); // Print the document


}
}

Trace — How It Works


Action empty full mutex
Initial state (N=3) 3 0 1
Student 1 submits job 2 1 1
Student 2 submits job 1 2 1
Student 3 submits job 0 3 1
Student 4 tries — BLOCKS on 0 (blocked) 3 1
wait(empty)
Printer processes job 1 1 2 1
Student 4 UNBLOCKS, adds job 0 3 1
Queue empty — Printer BLOCKS 3 0 (blocked) 1
on wait(full)
Student submits — Printer 2 1 1
UNBLOCKS

How Semaphores Solve the 3 Problems


Problem Semaphore Solution
Full Queue Prevention wait(empty) before adding — if empty=0 (queue full), producer
BLOCKS automatically. signal(empty) by consumer releases it.
Empty Queue Prevention wait(full) before consuming — if full=0 (queue empty), printer
BLOCKS automatically. signal(full) by producer releases it.
Race Condition Prevention wait(mutex) before queue access, signal(mutex) after — ensures
only one process modifies queue at a time. Prevents data corruption
when multiple students submit simultaneously.

Why This Is the Complete Solution


✓ No deadlock: mutex is always released before signaling empty/full ✓ No starvation: counting
semaphores ensure all producers/consumers eventually get access ✓ Mutual exclusion: mutex
binary semaphore prevents simultaneous queue access ✓ Bounded buffer: empty and full
semaphores enforce queue size limit N IMPORTANT: Always acquire mutex AFTER
wait(empty)/wait(full), NEVER before. Reversing this order causes DEADLOCK!

Good luck! 🎯 — OS Module 1 Notes + All 5 Questions Solved

You might also like