0% found this document useful (0 votes)
16 views10 pages

Operating System

The document provides a comprehensive overview of key concepts in operating systems, including processes, context switching, deadlocks, and file management. It explains various operations on files, characteristics of operating systems, and scheduling methods, along with comparisons between multiprogramming and multiprocessing. Additionally, it covers memory management techniques such as paging and segmentation, as well as deadlock handling strategies and file structures.
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)
16 views10 pages

Operating System

The document provides a comprehensive overview of key concepts in operating systems, including processes, context switching, deadlocks, and file management. It explains various operations on files, characteristics of operating systems, and scheduling methods, along with comparisons between multiprogramming and multiprocessing. Additionally, it covers memory management techniques such as paging and segmentation, as well as deadlock handling strategies and file structures.
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
You are on page 1/ 10

Q1 8.

Append data to a file

a) Define process:

A process is a program in execution. It is an e) What is meant by rotational latency in


active entity that includes the program disk scheduling?
code, current activity (program counter,
Rotational latency is the time taken by the
registers), memory, and other resources like
disk to rotate the correct sector under the
open files.
read-write head after the seek operation. It
depends on the rotation speed of the disk.

b) What is context switch?

A context switch is the process of saving the f) Define critical section:


state of a currently running process and
A critical section is a part of a program
loading the state of another process. It
where the shared resources are accessed.
allows the CPU to switch from one process
Only one process is allowed in the critical
to another, enabling multitasking.
section at a time to avoid race conditions.

c) What is a page frame?


g) State Belady’s anomaly:
A page frame is a fixed-size block of physical
Belady’s anomaly refers to the situation
memory (RAM) used in virtual memory
where increasing the number of page
systems. The logical memory (pages) is
frames results in an increase in the number
mapped to these physical memory blocks
of page faults in certain page replacement
(frames).
algorithms (e.g., FIFO).

d) List various operations on files:


h) List any 4 characteristics of Operating
1. Create a file System:

2. Open a file 1. Multitasking – Ability to execute


multiple tasks simultaneously.
3. Read from a file
2. Resource Management – Manages
4. Write to a file
CPU, memory, I/O devices.
5. Close a file
3. User Interface – Provides interface
6. Delete a file between user and hardware.

7. Rename a file
4. Security – Ensures unauthorized  It supervises performance, handles
access is prevented. errors, and manages files and
devices.

 It provides a user interface and


i) Define deadlock:
ensures security and protection.
A deadlock is a situation where a group of
In short, the OS ensures optimal use of
processes are blocked forever, each waiting
system resources while providing an
for a resource held by the other, creating a
environment for program execution—just
cycle of dependency.
like a good manager ensures smooth
operations in an organization.

j) What is the role of operating system?

The Operating System (OS) acts as an b) What is scheduling? Compare short term
interface between the user and hardware. scheduler with medium term scheduler.
Its roles include:
Scheduling is the process of selecting
 Managing hardware and software processes from the queue and allocating
resources system resources (especially CPU) to them.

 Providing a user interface Comparison:

 Controlling peripheral devices Short-Term Medium-Term


Feature
Scheduler Scheduler
 Managing files and processes

 Ensuring system security and Also Called CPU Scheduler Swapper


stability Selects process
Suspends and
Q2 from ready
Function resumes
queue to
a) ‘Operating system is like a manager of processes
execute
the computer system’. Explain.
Runs very
An Operating System (OS) acts like a Runs
Frequency frequently
manager by controlling and coordinating occasionally
(milliseconds)
the use of hardware and software
resources. Just like a manager in a company: Not time-
Speed Must be fast
critical
 It allocates resources (CPU, memory,
I/O) to various programs and users. Location of Selects from Moves
Processes ready state between ready
 It schedules tasks efficiently to
and
ensure smooth execution.
Short-Term Medium-Term | Process ID |
Feature
Scheduler Scheduler
+-------------------------+
suspended | Process State |
states
+-------------------------+

| Program Counter |
c) Draw and explain Process Control Block
(PCB): +-------------------------+

Process Control Block (PCB): | CPU Registers |

A PCB is a data structure maintained by the +-------------------------+


OS to keep information about a process. | Memory Management Info |
Contents of PCB: +-------------------------+
 Process ID – Unique identifier for | I/O Status Info |
the process
+-------------------------+
 Process State – Ready, Running,
Waiting, etc. | Accounting Info |

 Program Counter – Address of the +-------------------------+


next instruction

 CPU Registers – Contents of all d) Compare multiprogramming with


process registers multiprocessing system:
 Memory Management Info – Base, Multiprogrammi Multiprocessi
limit registers, page tables Feature
ng ng
 I/O Status Info – List of I/O devices Multiple CPUs
allocated Multiple
execute
Definition programs run on
 Accounting Info – CPU usage, time programs
a single CPU
limits, job priority simultaneously

Diagram: CPU Two or more


Single
Count CPUs
pgsql

CopyEdit

+-------------------------+
Multiprogrammi Multiprocessi v |
Feature
ng ng
+-------------+ Event occurs
No true True | Running |------------------->+
Parallelis parallelism; CPU parallelism;
m switches processes can +-------------+
between tasks run in parallel |
Increases v
Increases CPU throughput
Efficiency +---------------+
utilization and
performance | Waiting |
More complex +---------------+
Complexit (hardware and
Less complex |
y OS support
needed) v

+-------------+

e) Draw and explain the process state | Terminated |


diagram:
+-------------+
Process State Diagram:
Explanation of States:
sql
 New – Process is being created.
CopyEdit
 Ready – Process is waiting to be
+-------------+ assigned CPU.

| New |  Running – Process is currently being


executed.
+-------------+
 Waiting (Blocked) – Waiting for an
|
event or I/O.
v
 Terminated – Process has finished
+-------------+ I/O or event wait execution.

| Ready |<-------------------+ a) Compare Internal and External


Fragmentation
+-------------+ |

| |
Internal External Order of execution based on burst time:
Factor
Fragmentation Fragmentation P2 → P4 → P3 → P5 → P1

Wasted CopyEdit
Wasted memory | P2 | P4 | P3 | P5 | P1 |
memory inside outside
Definition 0 1 2 4 9 19
allocated allocated blocks
blocks. (between
them).
ii) Average Turnaround Time and Waiting
Due to fixed- Due to variable- Time
Cause size memory sized memory
allocation. allocation. Waitin
Burs Turnaroun
Proces Completio g Time
Allocating 100 Multiple small t d Time (CT
s n Time (TAT -
KB block for a free spaces Time - AT)
BT)
Example 90 KB process can't satisfy a
→ 10 KB is request of 100 P2 1 1 1 0
wasted. KB. P4 1 2 2 1
Use paging or Use compaction P3 2 4 4 2
Solution better block- or
fitting strategy. segmentation. P5 5 9 9 4

P1 10 19 19 9

b) Consider the following processes and Average Turnaround Time = (1 + 2 + 4 + 9 +


burst times: 19) / 5 = 7 ms
Average Waiting Time = (0 + 1 + 2 + 4 + 9) /
Process Burst Time
5 = 3.2 ms
P1 10 ms

P2 1 ms c) Explain Semaphores and Its Types


P3 2 ms A semaphore is a synchronization
mechanism used to manage access to
P4 1 ms
shared resources in concurrent systems.
P5 5 ms
Types of Semaphores:
All processes arrive at time 0.
1. Binary Semaphore (Mutex):
i) Gantt Chart using SJF (Shortest Job First):
o Takes only 0 or 1 values.
o Used for mutual exclusion o Break one of the four
(one process at a time). necessary conditions.

2. Counting Semaphore: o Example: Request all


resources at once (avoid Hold
o Can take non-negative
and Wait).
integer values.
2. Deadlock Avoidance:
o Useful for managing a pool of
resources. o Use Banker’s Algorithm to
ensure system stays in a safe
Semaphore Operations:
state.
 wait(S) or P(S) → Decreases the
3. Deadlock Detection and Recovery:
value; blocks if value < 0.
o Allow deadlocks to happen,
 signal(S) or V(S) → Increases the
detect them using a wait-for
value; unblocks a waiting process if
graph, and:
any.
 Kill a process
Example:
 Rollback a process
cpp
 Preempt resources
CopyEdit
4. Ignore the Problem:
wait(S); // enter critical section
o Let deadlocks occur and
// critical section
reboot system when
signal(S); // leave critical section detected (used in simple
systems).

d) What is Deadlock? Explain Various


Deadlock Handling Techniques e) Types of Directory Structures:

Deadlock: 1. Single-Level Directory:

A condition where two or more processes o All files in one directory.


are waiting indefinitely for resources held
o Simple, but name conflicts
by each other.
occur easily.
Deadlock Handling Techniques:
2. Two-Level Directory:
1. Deadlock Prevention:
o Separate directory for each
user.
o Better file organization.  Sequential access only (no random
access).
3. Tree-Structured Directory:
 Extra space for storing pointers.
o Hierarchical directories with
sub-directories.  Possibility of broken links or
corrupted pointers.
o Most common in modern OS.
Diagram:
4. Acyclic Graph Directory:
css
o Shared files/directories via
links. CopyEdit

o No cycles allowed. [Block 5 | → 12] → [Block 12 | → 20] →


[Block 20 | → null]
5. General Graph Directory:

o Like acyclic but allows cycles.


b) Compare Paging and Segmentation
o Complex and needs garbage
collection Feature Paging Segmentation

Q4 Divides Divides
a) Explain Linked Allocation in Files memory into memory into
Division Basis
fixed-size variable-size
Linked Allocation is a method of file storage pages segments
on disk where each file is a linked list of
disk blocks, which may be scattered All pages are Segments
Size
anywhere on the disk. equal size vary in size

How it works: Reflects user’s


Invisible to logical
 Each file starts with a start block. User View
the user program
 Every block contains a pointer to the structure
next block.
Causes Causes
 The last block has a null pointer. Fragmentatio internal external
n fragmentatio fragmentatio
Advantages:
n n
 No external fragmentation.
Segment
Table Used Page Table
 Files can grow easily. Table
Disadvantages: Access Type Mainly Supports
Feature Paging Segmentation 1. Sequential File: Data is stored in
sequence (e.g., text files).
random random and
access logical access 2. Indexed File: Uses index to access
data (like a book index).

3. Hashed File: Uses a hash function


c) Apply FCFS Disk Scheduling (Request for direct access.
Queue: 84, 145, 89, 168, 93, 128, 100, 68;
Head at 125) Basic Diagram:

Initial head position: 125 pgsql

Request Order (FCFS): 84 → 145 → 89 → CopyEdit


168 → 93 → 128 → 100 → 68 [ Directory Entry ] → [ File Name | Type |
Head Movement Calculation: Location | Size ]

 |125 - 84| = 41 ↓

 |84 - 145| = 61 +----------------------+

 |145 - 89| = 56 | Data Block | Pointer |

 |89 - 168| = 79 +----------------------+

 |168 - 93| = 75 ↓

 |93 - 128| = 35 +----------------------+

 |128 - 100| = 28 | Data Block | Pointer |

 |100 - 68| = 32 +----------------------+

Total Head Movement = This structure supports different file types


and access methods (sequential, random).
41 + 61 + 56 + 79 + 75 + 35 + 28 + 32 = 407
tracks
e) Page Replacement (FIFO)

d) Explain File Structure with Diagram Page reference string: 9, 2, 3, 4, 2, 5, 2, 6, 4,


5, 2, 5, 4, 3, 4, 2, 3, 9, 2, 3
File Structure refers to the logical layout of Page frames: 4
a file system used to organize and store
files. FIFO Algorithm Steps:

Types of File Structures: Let’s simulate step-by-step:


Memory (FIFO SPOOL stands for Simultaneous Peripheral
Step Page Page Fault
Order) Operations On-Line.
It is a process where data is temporarily
1 9 9 ✅
held in a buffer (usually a disk) before being
2 2 9, 2 ✅ sent to a device like a printer or plotter.

3 3 9, 2, 3 ✅ How It Works:

4 4 9, 2, 3, 4 ✅  Jobs are queued in the buffer.

 Devices process one job at a time


5 2 9, 2, 3, 4 ❌
from the queue.
6 5 2, 3, 4, 5 ✅ (remove 9)
 Enables asynchronous data flow
7 2 2, 3, 4, 5 ❌ between slow devices and fast CPUs.

8 6 3, 4, 5, 6 ✅ (remove 2) Example:

9 4 3, 4, 5, 6 ❌ When printing multiple documents, the OS


spools print jobs to the printer queue.
10 5 3, 4, 5, 6 ❌
Advantages:
11 2 4, 5, 6, 2 ✅ (remove 3)
 Efficient device usage.
12 5 4, 5, 6, 2 ❌
 Enables multiprogramming.
13 4 4, 5, 6, 2 ❌
 Prevents device contention.
14 3 5, 6, 2, 3 ✅ (remove 4)

15 4 6, 2, 3, 4 ✅ (remove 5) b) Dining Philosopher’s Problem


16 2 6, 2, 3, 4 ❌ A classic synchronization problem used to
illustrate deadlock and resource starvation
17 3 6, 2, 3, 4 ❌
in concurrent systems.
18 9 2, 3, 4, 9 ✅ (remove 6)
Setup:
19 2 2, 3, 4, 9 ❌
 Five philosophers sit at a round
20 3 2, 3, 4, 9 ❌ table.

TOTAL PAGE FAULT 10  A fork is placed between each pair.

Q5  Each philosopher needs two forks to


eat.
a) Spooling
Problem:
If each philosopher picks up one fork and
waits for the other, deadlock may occur.

Solutions:

 Allow at most 4 philosophers to sit


at the table at once.

 Pick up both forks together (atomic


action).

 Use semaphores or mutexes to


control access to forks.

c) Contiguous Memory Allocation

A memory management technique where


each process is allocated a single
continuous block of memory.

Features:

 Simple to implement.

 Fast access due to adjacent memory


blocks.

Problems:

 External fragmentation: Free


memory is scattered.

 Memory compaction may be


needed to merge free blocks.

Types:

1. Fixed Partitioning: Memory is


divided into fixed-size blocks.

2. Variable Partitioning: Memory


blocks vary in size based on process
needs.

You might also like