File Systems and IPC

Back

Loading concept...

πŸ—„οΈ Operating Systems: File Systems & IPC

The Library of Your Computer

Imagine your computer is a giant library. Every book, every picture, every song you save is stored in this library. But how does the library know where everything is? How do the librarians (programs) talk to each other when they need help? That’s what we’ll discover today!


πŸ“š What is a File System?

Think of a file system as the organizing system for your library. Without it, books would be scattered everywhereβ€”on the floor, on tables, in random piles. Nobody could find anything!

The Three Big Jobs of a File System

  1. Names things β€” Every file gets a name, like β€œbirthday_photo.jpg”
  2. Remembers where things are β€” Tracks exactly which shelf (disk location) holds each file
  3. Keeps things safe β€” Makes sure nobody erases your homework by accident!
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     YOUR COMPUTER           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚   FILE SYSTEM       β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”‚    β”‚
β”‚  β”‚  β”‚πŸ“„β”‚ β”‚πŸ–ΌοΈβ”‚ β”‚πŸŽ΅β”‚  β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜  β”‚    β”‚
β”‚  β”‚  Names + Locations   β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Real Life Example:

  • When you save a game, the file system picks a spot on your hard drive
  • It writes down: β€œGame save is at location 1234”
  • Later, when you load the game, it looks up location 1234 instantly!

πŸ”§ File Operations: What Can You Do With Files?

Just like you can do things with library books, you can do things with files!

The Six Magic Actions

Action What It Does Library Example
CREATE Make a new file Getting a brand new blank notebook
OPEN Start using a file Taking a book off the shelf
READ Look at what’s inside Reading the book pages
WRITE Add or change content Writing in your notebook
CLOSE Finish using the file Putting the book back
DELETE Remove the file Throwing the book away

How Opening a File Works

graph TD A["You click 'Open'"] --> B["OS finds file location"] B --> C["OS reads from disk"] C --> D["Data loaded into memory"] D --> E["You see your file!"]

Example: Opening a photo

  1. You double-click β€œvacation.jpg”
  2. File system looks up: β€œvacation.jpg is at disk sector 5678”
  3. It reads that sector into your computer’s fast memory
  4. Photo app displays your picture!

🌳 Directory Structure: Folders Inside Folders

A directory is just a fancy word for folder. And folders can contain other foldersβ€”like Russian nesting dolls! πŸͺ†

The Tree Shape

Your computer’s files form a tree shape, starting from one main folder called the root.

/  (root - the very top)
β”œβ”€β”€ πŸ“ Users
β”‚   β”œβ”€β”€ πŸ“ Alice
β”‚   β”‚   β”œβ”€β”€ πŸ“„ homework.doc
β”‚   β”‚   └── πŸ“ Photos
β”‚   β”‚       └── πŸ–ΌοΈ cat.jpg
β”‚   └── πŸ“ Bob
β”‚       └── 🎡 song.mp3
β”œβ”€β”€ πŸ“ Programs
β”‚   └── πŸ“± games
└── πŸ“ System

Absolute vs Relative Paths

Think of paths like addresses:

Path Type What It Means Example
Absolute Full address from root /Users/Alice/Photos/cat.jpg
Relative Directions from where you ARE Photos/cat.jpg (if you’re in Alice’s folder)

Simple Example:

  • Absolute path: β€œ123 Main Street, New York, USA”
  • Relative path: β€œGo two blocks left, then turn right”

πŸ’Ύ File Allocation Methods: Where Do Files Live?

When you save a file, the computer needs to find empty space on the disk. There are three main ways to do this!

1. Contiguous Allocation (All Together)

Like reserving seats next to each other at a movie theater. 🎬

Disk: [FILE A][FILE A][FILE A][empty][empty][FILE B][FILE B]
       ↑─────────────────────↑
       File A lives in seats 0-2

βœ… Good: Super fast to read (everything’s together!) ❌ Bad: Hard to grow files, creates gaps (fragmentation)

2. Linked Allocation (Follow the Chain)

Each piece points to the next piece, like a treasure hunt! πŸ—ΊοΈ

Block 5: [Data] β†’ points to Block 12
Block 12: [Data] β†’ points to Block 3
Block 3: [Data] β†’ END

βœ… Good: Files can be anywhere, easy to grow ❌ Bad: Slow (must follow each link), one broken link = lost file!

3. Indexed Allocation (The Master List)

One special block holds a list of all locationsβ€”like a table of contents! πŸ“‹

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  INDEX BLOCK    β”‚
β”‚  Block 0: loc 5 β”‚
β”‚  Block 1: loc 12β”‚
β”‚  Block 2: loc 3 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βœ… Good: Fast random access, no wasted pointers ❌ Bad: Index block takes space, big files need multiple index blocks

graph TD subgraph Contiguous A1["Block 1"] --> A2["Block 2"] --> A3["Block 3"] end subgraph Linked B1["Block 5"] -.-> B2["Block 12"] -.-> B3["Block 3"] end subgraph Indexed C0["Index"] --> C1["Block 5"] C0 --> C2["Block 12"] C0 --> C3["Block 3"] end

🎑 Disk Scheduling: Who Gets the Disk Next?

Your hard disk has a read/write head that moves across the disk like a record player needle. πŸ’Ώ

When multiple programs want to read/write at the same time, who goes first?

The Problem

Imagine the read head is at track 50. Three programs want:

  • Program A: Track 20
  • Program B: Track 100
  • Program C: Track 30

Scheduling Algorithms

1. FCFS (First Come, First Served)

Serve requests in the order they arrive. Simple but not efficient!

Head at 50 β†’ 20 β†’ 100 β†’ 30
Movement: 30 + 80 + 70 = 180 tracks total πŸ˜“

2. SSTF (Shortest Seek Time First)

Go to the closest request next. Greedy but faster!

Head at 50 β†’ 30 β†’ 20 β†’ 100
Movement: 20 + 10 + 80 = 110 tracks total 😊

3. SCAN (The Elevator)

Move in one direction until the end, then reverse. Like an elevator!

Head at 50 β†’ goes right to 100 β†’ then left to 30 β†’ 20

4. C-SCAN (Circular SCAN)

Go one direction, jump back to start, repeat. Always moving forward!

50 β†’ 100 β†’ [jump to 0] β†’ 20 β†’ 30
graph LR subgraph FCFS F1["50"] --> F2["20"] --> F3["100"] --> F4["30"] end subgraph SSTF S1["50"] --> S2["30"] --> S3["20"] --> S4["100"] end

Real Life: Think of SCAN like an elevatorβ€”it doesn’t go up, down, up, down randomly. It goes all the way up, then all the way down!


πŸ—£οΈ Inter-Process Communication (IPC): Programs Talking to Each Other

When two programs need to share information, they use IPC. It’s like how people communicate!

Why Do Programs Need to Talk?

  • A web browser asks the download manager to fetch a file
  • Your music player tells the volume control to go louder
  • A game’s graphics engine talks to the physics engine

The Six Ways Programs Communicate

1. Pipes (One-Way Tunnel) πŸš‡

Data flows in one direction only, like water in a pipe.

[Program A] ──data──► [Program B]
   Writer              Reader

Example: ls | grep "txt" β€” the output of ls flows INTO grep

2. Named Pipes (FIFO) πŸ“¬

Like a pipe, but with a nameβ€”any program that knows the name can use it!

[Any Program] ──► /tmp/my_pipe ──► [Any Program]

3. Shared Memory πŸ“¦

Two programs share the same chunk of memoryβ€”the fastest method!

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      SHARED MEMORY          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”     β”‚
β”‚   β”‚Prog β”‚ ←──► β”‚Prog β”‚     β”‚
β”‚   β”‚  A  β”‚      β”‚  B  β”‚     β”‚
β”‚   β””β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Super fast! But need to be carefulβ€”both writing at once = chaos!

4. Message Queues πŸ“¨

Programs leave messages in a mailbox for others to pick up.

Program A drops message β†’ [QUEUE: msg1, msg2] β†’ Program B reads

Like: Leaving sticky notes on someone’s desk

5. Semaphores 🚦

A traffic light for programs. Controls who can access shared things.

Green (1): Go ahead and use the resource
Red (0): Wait, someone else is using it

Example: Only one program prints at a time, so pages don’t get mixed up!

6. Sockets πŸ”Œ

Communication across the networkβ€”even between different computers!

[Your Computer] ←─internet─→ [Server Computer]
     Client                      Server

Example: Your browser (client) talks to google.com (server) using sockets!


🎯 Quick Comparison Table

IPC Method Speed Across Network? Best For
Pipes Fast ❌ No Parent-child processes
Named Pipes Fast ❌ No Unrelated processes
Shared Memory ⚑ Fastest ❌ No Large data, same machine
Message Queues Medium ❌ No Async messaging
Semaphores N/A ❌ No Synchronization only
Sockets Slower βœ… Yes Network communication

πŸŽ‰ You Did It!

Now you understand how your computer:

  1. Organizes files in a tree structure
  2. Stores files using allocation methods
  3. Schedules disk access efficiently
  4. Lets programs talk to each other

Think of your computer as a busy library with chatty librariansβ€”and now you know exactly how they keep everything running smoothly! πŸ“šβœ¨


🧠 Key Takeaways

  • File System = The organizing system that names, locates, and protects your files
  • File Operations = CREATE, OPEN, READ, WRITE, CLOSE, DELETE
  • Directory Structure = Tree of folders starting from root (/)
  • Allocation Methods = Contiguous (fast), Linked (flexible), Indexed (balanced)
  • Disk Scheduling = FCFS, SSTF, SCAN, C-SCAN (like elevator algorithms)
  • IPC = How programs communicate: pipes, shared memory, sockets, and more!

Loading story...

Story - Premium Content

Please sign in to view this story and start learning.

Upgrade to Premium to unlock full access to all stories.

Stay Tuned!

Story is coming soon.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.