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

OS Unit - 1 (VT)

The document discusses the directory structure in operating systems, outlining its importance for file management and various types of directory structures including single-level, two-level, tree-structured, acyclic graph, and general graph. It also covers directory implementation methods, recovery techniques, and classical synchronization problems such as the producer-consumer, readers-writers, and dining philosophers problems, along with their solutions using semaphores. Overall, it emphasizes the need for efficient file organization and process synchronization in operating systems.

Uploaded by

vanshthakral2004
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)
28 views10 pages

OS Unit - 1 (VT)

The document discusses the directory structure in operating systems, outlining its importance for file management and various types of directory structures including single-level, two-level, tree-structured, acyclic graph, and general graph. It also covers directory implementation methods, recovery techniques, and classical synchronization problems such as the producer-consumer, readers-writers, and dining philosophers problems, along with their solutions using semaphores. Overall, it emphasizes the need for efficient file organization and process synchronization in operating systems.

Uploaded by

vanshthakral2004
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

OPERATING SYSTEM

UNIT -1
Directory Structure in Operating System (OS)

A directory is a system that organizes and manages files in an OS. It allows easy access, storage, and
retrieval of files. The directory structure is essential for file management, ensuring users can
efficiently locate and manage their files.

Key Points of Directory Structure

 File Naming: Users can freely assign names.

 File Sharing & Access: Supports multiple users.

 Supported Operations:

o Creating: Add new files/folders.

o Searching: Locate files in a directory.

o Deleting: Remove unnecessary files/folders.

o Listing: View stored files.

o Renaming: Change file/folder names.

o Linking: Allow files in multiple directories.

o Unlinking: Remove file links.

Types of Directory Structures in OS

1. Single-Level Directory Structure

 Definition: All files are stored in a single directory (root directory).

 Characteristics: Simple and easy to use.


Advantages:

 Easy Implementation: Simple to manage.

 Simple Searching: Quick file lookup.

 Basic Operations: Supports essential tasks.

Disadvantages:

 Naming Conflicts: Duplicate names possible.

 Search Difficulty: Hard to find files in large directories.

 No Grouping: Lacks file categorization.

2. Two-Level Directory Structure

 Definition: Each user gets their own directory, called a User File Directory (UFD). A Master
File Directory (MFD) stores all user directories.

Advantages:

 No Naming Conflicts: Same names allowed.


 Privacy: Restricted file access.

 Easy Searching: Simplified within directories.

Disadvantages:

 No Sharing: Files can't be shared.

 No Subdirectories: Limited organization.

 Scalability Issues: Not expandable.

3. Tree-Structured Directory

 Definition: Extends the two-level structure by allowing subdirectories. The hierarchy starts
from a root directory, branching into user directories and subdirectories.

Advantages:

 Subdirectories: Better organization.

 Fewer Naming Conflicts: Reduced duplicate names.

 Better Grouping: Organized file storage.

Disadvantages:

 No Direct Sharing: Limited user access.

 Complex Navigation: Deep directories are inefficient.

 Rigid Hierarchy: Not flexible for all files.

4. Acyclic Graph Directory Structure


 Definition: Allows directories and files to have multiple parent directories. Supports file
sharing between users using links.

 Types of Links:

o Hard Link: A physical link to a file that remains until all references are deleted.

o Symbolic (Soft) Link: A logical link that leaves a "dangling" reference if the original
file is deleted.

Advantages:

 File Sharing: Enables user access.

 Multiple Paths: Access files in different ways.

Disadvantages:

 Complex Deletion: Shared files are harder to remove.

 Dangling Links: Broken references may occur.

5. General Graph Directory Structure

 Definition: Enhances the Acyclic Graph structure by allowing cyclic links, meaning a directory
can reference itself. Offers more flexibility in file organization.
Path Types:

 Absolute Path: Starts from the root directory.


 Relative Path: Based on the file’s or user’s directory.

Advantages:

 Highly Flexible: Most adaptable structure.

 Multiple Access Paths: Access files in various ways.

Disadvantages:

 Complex Storage Calculation: Hard to track space.

 Frequent Garbage Collection: Needs regular cleanup.

 High Maintenance Cost: More upkeep required.

# Directory Implementation in OS

1️Singly Linked List

 Stores file names as a list with pointers.

 Good for: Deleting files quickly.


 Bad for: Slow searching (linear search).

2️ Hash Table

 Uses keys to find files quickly.

 Good for: Fast searching.

 Bad for: Fixed size, depends on good hashing.

Recovery in OS (Brief)

Recovery ensures data consistency after system failures.

🔹 Methods:
1️Backups → Save copies of data to restore lost files.
2️Consistency Checks → Scan directories to detect & fix errors.
3️Log-Based Recovery → Keeps a record of file operations to undo/redo actions.

✅ Prevents data loss & maintains file system integrity. 🚀

Classical Synchronization Problems

Synchronization is needed in OS to manage multiple processes and prevent conflicts when accessing
shared resources. The main problems are:

1️ Producer-Consumer Problem / Bounded Buffer Problem

📌 Problem: A Producer creates items and puts them in a buffer. A Consumer takes items from the
buffer. They should not interfere with each other.

🔹 Solution using Semaphores:

 mutex → Controls access to the buffer.

 full → Tracks filled slots.

 empty → Tracks empty slots.

🔹 Producer Code:

do {

wait(empty); // Wait if buffer is full

wait(mutex); // Lock buffer

// Produce & place item in buffer

signal(mutex); // Unlock buffer

signal(full); // Increase full count

} while(true);

🔹 Consumer Code:

do {

wait(full); // Wait if buffer is empty

wait(mutex); // Lock buffer

// Consume item from buffer


signal(mutex); // Unlock buffer

signal(empty); // Increase empty count

} while(true);

✅ Ensures producer & consumer don’t access buffer at the same time.

2️ Readers-Writers Problem

📌 Problem:

 Readers can read at the same time.

 Writers must write alone (no readers or writers can interfere).

🔹 Solution (Readers Preference)

 mutex → Controls access to reader count.

 wrt → Ensures only one writer at a time.

 readcnt → Tracks number of readers.

🔹 Writer Code:

do {

wait(wrt); // Wait if another writer is writing

// Perform writing

signal(wrt); // Allow other writers/readers

} while(true);

🔹 Reader Code:

do {

wait(mutex);

readcnt++;

if (readcnt == 1) wait(wrt); // First reader blocks writers

signal(mutex);

// Perform reading
wait(mutex);

readcnt--;

if (readcnt == 0) signal(wrt); // Last reader allows writers

signal(mutex);

} while(true);

✅ Readers get priority & multiple readers can read simultaneously.

3️Dining Philosophers Problem

📌 Problem:

 N philosophers sitting around a table, each needs 2 chopsticks to eat.

 They must avoid deadlocks (where all hold one chopstick but can’t proceed).

🔹 Solution using Semaphores:

 Each chopstick is a semaphore.

 A philosopher must pick up both chopsticks before eating.

🔹 Philosopher Code:
do {

THINK;

wait(chopstick[i]);

wait(chopstick[(i+1) % 5]); // Pick both chopsticks

EAT;

signal(chopstick[i]);

signal(chopstick[(i+1) % 5]); // Put down chopsticks

} while(true);

✅ Prevents deadlock by controlling chopstick access.

Summary (Quick Revision)

Problem Issue Solution

Producer-
Producer & consumer must not interfere Semaphores: mutex, full, empty
Consumer

Multiple readers allowed, only one writer at a Semaphores: mutex, wrt,


Readers-Writers
time readcnt

Dining
Avoid deadlock while using chopsticks Semaphores for chopsticks
Philosophers

You might also like