A) Operating System - Definition & Main Functions
A) Operating System - Definition & Main Functions
Definition (≈ 1 mark)
An Operating System (OS) is system software that acts as an intermediary between
computer hardware and the user/programs, managing all hardware resources and providing a
convenient, efficient environment in which programs can be executed.
Main Functions (explain any six well for full marks, ≈ 5 marks)
Definition (≈ 1 mark)
A system call is a controlled entry-point through which a user-level process requests a
service from the kernel, switching from user mode to kernel mode to execute privileged
operations (e.g., I/O, memory management).
Classification of System Calls (explain any five categories with examples, ≈ 5 marks)
Typical POSIX/Linux Examples & Brief
Category Purpose
Role
fork() duplicates current process; execve()
Create, terminate, and
overlays a new program image; exit()
1. Process Control manage
terminates; waitpid() synchronises with
processes/threads.
child; pthread_create() (threads).
open(), creat() (create/obtain file
2. File Manipulate
descriptor); read(), write() (I/O); lseek()
Management files/directories.
(reposition); close(); unlink() (delete).
ioctl() configures device parameters;
3. Device (I/O) Access and control
read()/write() on special files; mmap() maps
Management peripheral devices.
device memory.
4. Information Obtain or alter misc. getpid(), gettimeofday(), uname();
Maintenance kernel data. settimeofday(); alarm() to schedule signals.
Exchange data between pipe(), shmget() (shared memory),
5. Communication
processes, local or msgsnd()/msgrcv() (message queues);
(Inter-Process)
remote. sockets: socket(), bind(), send(), recv().
chmod(), chown(), setuid(), umask() set
6. Protection & Control access
default rights; capset() to adjust Linux
Security permissions.
capabilities.
Here are the full 6-mark answers for both questions from the subject Operating System:
Introduction (1 mark)
A process is a program in execution. During its lifetime, a process goes through various
states that define what it is currently doing (e.g., waiting, running, etc.). The Operating
System uses a Process Control Block (PCB) to track the current state of each process.
1. New The process is being created and has not yet been admitted to the ready queue.
The process is currently being executed by the CPU. Only one process can be in
3. Running
this state at a time per CPU core.
4. Waiting /
The process is waiting for an I/O event or some resource to become available.
Blocked
5. Terminated /
The process has finished execution and is being removed from the system.
Exit
Transitions (2 marks)
Transition Trigger
Exam Tip: Label the diagram neatly and explain transitions with keywords like admit,
dispatch, exit, I/O wait, interrupt to fetch full marks.
b) Compare FCFS, SJF, RR, and Priority Scheduling with Gantt Chart and
Calculation
P1 0 ms 5 ms 2
P2 1 ms 3 ms 1
P3 2 ms 8 ms 3
P4 3 ms 6 ms 4
Gantt Chart:
| P1 | P2 | P3 | P4 |
0 5 8 16 22
Calculations:
P1 0 5
P2 4 7
P3 6 14
P4 13 19
Average Waiting Time = (0+4+6+13)/4 = 5.75 ms
Average Turnaround Time = (5+7+14+19)/4 = 11.25 ms
Order: P1 → P2 → P4 → P3
Gantt Chart:
| P1 | P2 | P4 | P3 |
0 5 8 14 22
Calculations:
P1 0 5
P2 4 7
P4 5 11
P3 6 14
Gantt Chart:
|P1|P2|P3|P4|P1|P3|P4|
0 4 7 11 15 16 20 22
Waiting Time:
P1 11 ms
P2 3 ms
P3 10 ms
P4 13 ms
4. Priority Scheduling
Order: P2 → P1 → P3 → P4
Gantt Chart:
| P2 | P1 | P3 | P4 |
1 4 9 17 23
Calculations:
P2 0 3
P1 3 8
P3 7 15
P4 14 20
This results in circular waiting, and no process can make progress, even though all of them
are technically "alive."
All four conditions must hold simultaneously for a deadlock to occur. These are:
Condition Description
1. Mutual At least one resource must be held in a non-shareable mode (only one process can
Exclusion use it at a time).
2. Hold and A process is holding at least one resource and is waiting to acquire additional
Wait resources that are currently being held by other processes.
3. No Resources cannot be forcibly taken away; they must be released voluntarily by the
Preemption process.
Condition Description
A circular chain of two or more processes exists, where each process is waiting for
4. Circular Wait
a resource held by the next process in the chain.
Example (1 mark)
Let’s consider two processes P1 and P2 and two resources R1 and R2.
Exam Tip: Always define deadlock, name all four conditions, and illustrate with a simple 2-
process, 2-resource example to secure full marks.
When multiple processes access shared resources, a Critical Section (CS) is the code
segment where the resource is accessed. To avoid race conditions, only one process must
enter the CS at a time.
Mutual Exclusion
Progress
Bounded Waiting
Peterson’s Solution Algorithm (3 marks)
// Shared Variables
boolean flag[2]; // flag[i] = true means Pi wants to enter
int turn; // indicates whose turn it is
// Critical Section
Explanation (2 marks)
Property How it is achieved in Peterson’s algorithm
Mutual Only one process can enter the CS because the other process will wait if flag[j]
Exclusion == true && turn == j.
If no process is in the CS, and one wants to enter, it will not be prevented by the
Progress
other.
Bounded
No process waits indefinitely. Turn alternates, ensuring fairness.
Waiting
Working Example
But since the last turn was set by P1, P0 gets a chance, enters CS, and sets flag[0] =
false upon exit.
Paging Segmentation
Memory is divided into fixed-size blocks called Memory is divided into variable-size blocks called
pages segments
It is mainly for physical memory management It reflects logical division (code, stack, data)
No external fragmentation, but may have internal No internal fragmentation, but may have external
fragmentation fragmentation
Tip: In exams, keep the points short, specific, and clearly contrasting. Stick to six key points
for full marks.
Concept:
The oldest loaded page is removed first when a new page needs to be loaded and
memory is full.
Easy to implement using a queue.
Example:
Given Page Reference String: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Assume 3 frames
Step-by-step:
1 1 1 Yes
2 2 1, 2 Yes
3 3 1, 2, 3 Yes
4 4 2, 3, 4 Yes
5 1 3, 4, 1 Yes
6 2 4, 1, 2 Yes
7 5 1, 2, 5 Yes
8 1 1, 2, 5 No
9 2 1, 2, 5 No
10 3 2, 5, 3 Yes
11 4 5, 3, 4 Yes
12 5 3, 4, 5 Yes
Concept:
Replaces the page that has not been used for the longest time in the past.
Uses time-stamp or stack for tracking usage.
1 1 1 Yes
2 2 1, 2 Yes
3 3 1, 2, 3 Yes
4 4 2, 3, 4 Yes
5 1 3, 4, 1 Yes
6 2 4, 1, 2 Yes
7 5 1, 2, 5 Yes
8 1 1, 2, 5 No
9 2 1, 2, 5 No
10 3 2, 5, 3 Yes
11 4 5, 3, 4 Yes
12 5 3, 4, 5 Yes
Total Page Faults: 10 (Same as FIFO in this case, but may vary in other strings)
Removes the oldest page Removes the least recently used page
Here are the full 6-mark answers for both questions from the Operating System subject:
a) Explain File Allocation Methods: Contiguous, Linked, and Indexed
Concept:
In contiguous allocation, each file occupies a set of consecutive blocks on the disk.
Example:
If a file requires 5 blocks and starts at block 10, it will occupy blocks 10 to 14.
Diagram:
Advantages:
Simple to implement.
Supports fast sequential and direct access.
Disadvantages:
Concept:
Each file is a linked list of disk blocks. Blocks can be scattered anywhere on disk.
Example:
A file is stored in blocks 9 → 16 → 1 → 10
Diagram:
Advantages:
No external fragmentation.
Files can easily grow dynamically.
Disadvantages:
Slow random access (no direct access).
Extra overhead for pointers in each block.
Risk of broken links or corruption.
Concept:
An index block contains all the pointers to the actual blocks of the file.
Example:
If file has data blocks at 5, 9, 13, 20, the index block holds those addresses.
Diagram:
[Index Block]
↓ ↓ ↓ ↓
[5] [9] [13] [20]
Advantages:
Disadvantages:
Exam Tip: Explain each method clearly, with diagrams and at least one
advantage/disadvantage for 6/6 marks.
Assume:
Explanation:
Order:
53 → 98 → 183 → 37 → 122 → 14 → 124 → 65 → 67
Diagram:
Disadvantage: Long total head movement; does not minimize seek time.
Explanation:
Diagram:
Explanation:
Head moves in one direction (e.g., toward 0), servicing all requests, then reverses.
Order:
53 → 37 → 14 → 0 → 65 → 67 → 98 → 122 → 124 → 183
Diagram:
Head Movement:
Disadvantage: Initial movement toward end (0) even if few requests are there.
Definition
An Operating System (OS) is system software that manages computer hardware, provides a
set of services to application programs, and acts as a user-friendly interface between users
and the machine.
Major Functions (state and elaborate any six for a 6-mark answer)
Device & I/O Device drivers, buffering/caching, spooling, I/O scheduling to overlap
4
Management CPU & I/O.
Resource Allocation & Fair distribution of CPU cycles, memory pages, I/O bandwidth; usage
6
Accounting statistics for billing/tuning.
Tip: Start with a crisp two-line definition, then discuss any six distinct functions with 2-3
sub-points each.
Definition
Change rights or
Protection Permissions & IDs chmod(), setuid(), capset()
privileges.
Mention that all modern OSes expose dozens of such syscalls, each identified by a unique
number in the syscall table.
1. User Programs run in user mode; they rely on the shell or other utilities to invoke
services.
2. The Shell reads commands, interprets scripts, and uses fork+exec to launch programs.
3. System Call Interface acts as the boundary: switches to kernel mode on a trap,
validates args.
4. Kernel Proper contains schedulers, memory manager, VFS layer, device drivers, and
IPC primitives.
5. Everything-is-a-file philosophy: devices, pipes, and sockets share a common file
descriptor API.
6. Separation of user vs kernel mode ensures protection and stability.
Performance hit
OS divided into
Clear abstraction due to layer THE system, early
hierarchical layers;
Layered boundaries; easier crossing; rigid Windows NT
each layer uses only
verification/testing. placement may be (hybrid layered).
lower-level services.
tricky.
Below are full-length, 6-mark-style answers for every point you asked.
(When you’re ready for the combined PDF in Times New Roman, just say the word.)
A program goes through well-defined states during its lifetime. The classic five-state model
is enough for most exam answers.
Inter-state events
• New → Ready : admitted by long-term scheduler
• Ready → Running : CPU scheduler selects process
• Running → Waiting : I/O or event wait
• Waiting → Ready : I/O completes (signal/interrupt)
• Running → Ready : time-slice expires (pre-emptive OS)
• Running → Terminated : finishes / killed
Exam hint: Name each state, draw arrows neatly, and label at least four event triggers
(admit, dispatch, I/O wait, interrupt, exit) to lock in full marks.
Assumed process set (same burst/arrival values used earlier so answers stay consistent):
P1 0 5 2
P2 1 3 1
P3 2 8 3
P4 3 6 4
(a) FCFS
Gantt chart
| P1 | P2 | P3 | P4 |
0 5 8 16 22
| P1 | P2 | P4 | P3 |
0 5 8 14 22
Average waiting = 9.25 ms (turnaround omitted in many syllabi for RR but can be derived
similarly).
Order : P2 → P1 → P3 → P4
| P2 | P1 | P3 | P4 |
1 4 9 17 23
FCFS 5.75 ms No No
RR (q = 4) 9.25 ms Yes No
PCB is the kernel-resident data structure that stores all information required to manage a
particular process.
Field Purpose
Process ID / Parent ID Unique identifiers for tracking & hierarchy (fork trees).
Memory Management Info Base & limit registers, page tables, segment tables, frame list.
Mention at least five distinct fields and their roles for a rock-solid 6-mark answer.
Inter-process communication (pipes, sockets) Natural communication via shared memory (needs
is comparatively slow. synchronisation).
Crash may bring down the entire process with all its
Failure usually crashes only that process.
threads.
Has its own PCB, kernel resources, and file Shares most kernel resources; each thread has a TCB
table copy. (Thread Control Block).
Here are the full 6-mark detailed answers for all questions from Unit 3 – Deadlock and
Synchronization in your Operating System syllabus:
Definition:
# Condition Explanation
Mutual At least one resource is held in a non-shareable mode—only one process can use
1
Exclusion it at a time.
A circular chain exists: P1 waits for a resource held by P2, P2 for P3, ..., Pn waits
4 Circular Wait
for P1.
Example:
Let P1 hold resource R1 and wait for R2; P2 holds R2 and waits for R1.
This forms a circular chain: P1 → R2 → P2 → R1 → P1 ⇒ Deadlock.
Definition:
The critical section is a part of the code where a process accesses shared resources (like
variables, files, etc.), and only one process should execute in it at a time to avoid race
conditions.
Shared variables:
flag[i] = true;
turn = j;
while (flag[j] && turn == j)
; // wait
// Critical Section
Properties Ensured:
Definition:
Types of Semaphores:
Type Description
Binary Semaphore Value is only 0 or 1 (acts like a mutex lock). Used for mutual exclusion.
Counting Value can be any non-negative integer. Used to control access to a resource with
Semaphore multiple instances.
Operations:
Operation Meaning
wait(S);
// critical section
signal(S);
Semaphores solve the critical section problem and avoid busy waiting in process
synchronization.
Goal:
Avoid deadlock by ensuring that resource allocation always leads to a safe state.
Data Structures:
Algorithm Steps:
1. Safety Algorithm:
o Work ← Available
o Finish[i] ← false for all i
o Find a process Pi such that:
Finish[i] == false
Need[i] ≤ Work
o If found:
Work += Allocation[i]
Finish[i] = true
o Repeat until all processes are finished or no such Pi exists.
2. If all Finish[i] == true: the system is in a safe state.
Example:
Advantages of RAG:
Here are the full 6-mark answers for all key questions in Unit 4 – Memory Management of
your Operating Systems syllabus:
Units Pages (logical), Frames (physical) Segments like code, stack, heap
Size All pages are of equal size Segments are of unequal size
Feature Paging Segmentation
Paging Diagram:
Logical Address
↓
+------------+
| Page No. | Offset |
+------------+
↓
Page Table
↓
+------------+
| Frame No. | Offset |
+------------+
↓
Physical Memory Accessed
Segmentation Diagram:
Logical Address
↓
+----------------+
| Segment No. | Offset |
+----------------+
↓
Segment Table
↓
+------------------+
| Base + Offset |
+------------------+
↓
Physical Memory Accessed
Mapping Logical → Physical via page/segment table Already mapped to memory location
Aspect Logical Address (Virtual) Physical Address (Real)
Accessibility Cannot access memory directly Accesses the real location in RAM
Security Provides protection and isolation Exposed only after address translation
7, 0, 1 → page fault
2 → 7 replaced
0 → no fault
3 → 0 replaced
0 → 1 replaced
4 → 2 replaced
2 → 3 replaced
3 → 0 replaced
0 → no fault
3 → no fault
2 → 4 replaced
Page Faults: 10
Replace the page that will not be used for the longest time in the future.
Page Faults: 7
(Minimum possible faults for this reference string with 3 frames)
Demand Paging:
Technique in virtual memory systems where pages are not loaded into RAM until
they are needed.
Reduces memory usage and load time.
Page Fault:
Occurs when:
Performance Impact:
Unused
Wasted inside allocated block Wasted between allocated blocks
Space
Allocating 100 bytes in a 128-byte 3 blocks of 200 KB free, but none is contiguous
Example
page → 28 bytes wasted to allocate a 300 KB process
Can Be
Using smaller block size Compaction or paging
Solved By
1. File-Allocation Methods
• External
File occupies one • Simple• Fast
fragmentation• File
Contiguous continuous run [Start … End] sequential & direct
size must be known;
of blocks. access
hard to extend
Single-Level All files in one directory. • Very simple • Name clashes; no grouping.
Acyclic Tree plus shared • Allows sharing (libraries, • Must avoid cycles; link
Graph subtrees using links. common data) maintenance overhead.
Key Fields
How It Works
4. Disk-Scheduling Algorithms
Assume initial head at 53; queue: 98, 183, 37, 122, 14, 124, 65, 67.
Movement
Algorithm Short Sketch Pros Cons
Pattern
Sweep in one
Uniform
direction only; Large jump
C-SCAN 53→65→67→98→…183→4999→0→14… response
jump to start overhead.
time
without service.
Similar
Like SCAN/C-SCAN Avoids
trade-offs to
LOOK / but stop at last unnecessary
53→37→14 then reverse 65→67→… SCAN/CSCAN
C-LOOK request before full-disk
but slightly
turning/jumping. sweep
less travel.
In answers, draw a line with tick marks (0- 4999) and plot head paths—it instantly earns
clarity marks.
5. Buffering vs Spooling
Aspect Buffering Spooling
Using memory buffers to hold data Putting I/O jobs on disk (queue) so devices
Definition
during I/O to match speed mismatch. (printers, plotters) work asynchronously.
Storage
Main memory (sometimes cache). Secondary storage (magnetic disk).
Location
Double buffering for disk reads, Print queue: many users “print” → files
Example
network packets. spooled → printer works one by one.