Inter-Process Communication (IPC) Why IPC? Processes have isolated memory, need to exchange info. Mechanisms: Pipes, Message Queues, Shared Memory, Signals, Sockets. Blocking: Process waits until operation completes. Non-Blocking: System call returns immediately with error if operation incomplete. Synchronous: Sender blocks until message received. Asynchronous: Sender sends and continues, receiver picks up later (often via buffering). Pipes Unidirectional FIFO channel. Anonymous: Parent-child only. Created via pipe() before fork() . Named (FIFOs): Unrelated processes. Created via mkfifo() in filesystem. Shell uses pipes ( | ) for command chaining. Message Queues Kernel-managed list of messages. Sender posts, receiver retrieves. Messages buffered. Decouples sender/receiver, supports asynchronous communication. Shared Memory Fastest IPC: common physical memory mapped into multiple processes' virtual spaces. No data copying. Requires explicit synchronization (e.g., semaphores) to prevent race conditions. Kernel uses tmpfs ($/dev/shm$) as backing store. Process P1 Shared Mem Process P2 Shared Mem Kernel Shared Mem Segment Signals Lightweight, async notifications (e.g., SIGINT , SIGKILL , SIGSEGV ). Sent via kill(pid, signal) , caught by signal handlers. Process Groups: Signals like SIGINT target entire foreground groups. File Systems - Core Concepts Disk Blocks: Basic storage unit (e.g., 4KB). Superblock: Contains FS metadata (size, block counts, type). Inode Table: Array of inodes. Each file/directory has one. Data Region: Stores file contents. Allocation Structures: Bitmaps (inode/data) track free/allocated units. Inode (Index Node) Identified by i-number . Stores file metadata: Permissions ( mode ), owner ( uid , gid ), size, link count. Timestamps: atime (access), mtime (modify), ctime (status change). Pointers to data blocks: Direct, Single-, Double-, Triple-indirect for scalability. Directory Organization A directory is a file containing <filename, inode_number> pairs. Includes "." (current dir) and ".." (parent dir) entries. File System Operations mkfs : Creates a file system. mount : Attaches a file system to the directory tree. open() : Finds inode, checks permissions, returns file descriptor (fd). read()/write() : Uses fd to access data blocks via inode pointers. Writes may allocate new blocks. fsync() : Flushes buffered file data to disk. rename() : Atomically changes file's path. stat() : Retrieves file metadata from inode. mkdir() / rmdir() : Create/delete directories. rmdir() requires empty dir. Hard Link ( link() ): New directory entry pointing to existing inode. Cannot span filesystems. Soft (Symbolic) Link ( symlink() ): Special file containing path to another file. Can span filesystems. lseek() : Repositions file offset for a given fd. Open File Table Kernel structure tracking all open files. File descriptors map to entries. fork() shares open file table entries, so parent/child share file offset. Memory Mapping ( mmap ) Maps a file/device into process's virtual address space. Allows direct memory access to file contents. Uses demand paging (pages loaded on access). Efficient for large files or shared memory. Storage Devices: HDDs Physical Structure: Platters (magnetic disks), Read/Write Heads, Spindle. Tracks & Sectors: Data organized in concentric tracks, divided into sectors (smallest unit, e.g., 512 bytes). Cylinder: Vertically aligned tracks across all platters. Zoned Data Recording (ZDR): Outer tracks have more sectors, higher data density, faster transfer rates. Addressing: CHS (Cylinder-Head-Sector): Physical addressing. LBA (Logical Block Addressing): Linear abstraction of sectors, handled by drive controller. Simplifies OS. Controller: Manages LBA mapping, bad block remapping, I/O queueing (optimizes head movement). Performance: Sequential reads are faster than random reads. Storage Devices: SSDs NAND Flash Memory: No moving parts. Data in pages within blocks. Reads: Very fast random access. Writes: Complex. Pages can only be written if empty. Entire blocks must be erased before reuse. Wear Leveling: Controller distributes writes evenly to prolong lifespan. Performance: Consistent, low-latency. No mechanical delays.