š Linear list Implementation in Directory (11 MCQs)
Sequential Storage of Directory Entries
Linear-list directory implementation stores directory entries one after another in a sequential structure. Each entry associates a filename with a file identifier or metadata reference. The file-system manager searches the list to locate requested names and updates entries during file creation, deletion, and renaming. This approach provides a simple directory-management mechanism suitable for small collections of files.
Why Simple Directory Structures Are Easy to Maintain
Complex search structures require additional metadata, memory, and maintenance operations. A linear list avoids these costs by storing entries in a straightforward sequence. Its main limitation appears when directories contain large numbers of files because searching may require examining many entries before finding the requested name.
Sequential Searching and Directory Modification
When a file is requested, the directory manager begins at the first entry and compares stored filenames with the requested name. A match identifies the associated file object. Creation normally checks that the name is unused before inserting a new entry. Deletion may remove an entry, mark it free, or compact the directory depending on implementation.
Searching a Directory Containing Five Hundred Files
Suppose a directory contains 500 entries and uses an unsorted linear list. Searching for a file in the last position requires examining all 500 entries. An unsuccessful search also requires examining the complete list. An average successful search under uniformly distributed names examines approximately 250 entries, illustrating the effect of directory size on lookup cost.
Low Metadata Overhead and Increasing Search Costs
Linear lists are easy to implement, require minimal auxiliary structures, and support straightforward insertion. However, lookup time increases linearly with the number of entries, making large directories less efficient. Deletion and space reuse also need careful management. Sorting can improve certain searches, but maintaining sorted order increases insertion and update complexity.
Clarifying Linear and Constant-Time Searching
'A linear list finds every file in constant time' is incorrect because searches may inspect all entries. 'Deleting an entry always requires moving every later entry' is incorrect because implementations can mark entries free or reuse them. 'An unsorted list supports binary search' is incorrect because binary search requires an appropriate ordered structure.
Exam Focus: Directory Lookup Complexity
Trace sequential filename comparisons and calculate the maximum or average number of entries examined. Explain insertion, deletion, and free-entry reuse. Identify the O(n) search complexity of an unsorted linear list. Compare linear lists with hash-table directories, particularly their metadata overhead and suitability for small or large directories.
Key Terms of Linear-List Directories
- Linear list - Sequential directory-entry structure.
- Directory entry - Stores a filename reference.
- Linear search - Examines entries sequentially.
- Insertion - Adds a directory entry.
- Deletion - Removes or marks an entry.
- O(n) - Linear search complexity.
š All Linear list Implementation in Directory MCQs
Q1. What term does a UNIX system use for the perāprocess entry that references an open file?
š Explanation: The correct answer is \file descriptor\ because UNIX assigns a small integer called a file descriptor to each open file in a process's table. \File handle\ is the Windows terminology, while an inode stores metadata on disk and a directory entry contains name information. Understanding the naming convention helps students recognize platformāspecific APIs and why code using descriptors works across UNIX environments.
Q2. Which component typically stores inode information for open files in a systemāwide structure?
š Explanation: The openāfile table holds the inodes and related data for files that are currently open. The superblock describes the overall file system, the inode cache may hold recently used inodes but is not the primary table, and the block bitmap tracks free blocks. Knowing the role of the openāfile table clarifies how the OS quickly accesses metadata without consulting disk each time.
Q3. Why does the operating system decrement the openācount when a process closes a file?
š Explanation: Decrementing the openācount records how many processes still have the file open. When the count reaches zero, the system knows it can release cached metadata and write back any pending changes. It does not delete the file or alter permissions; those actions occur only on explicit system calls. Recognizing this referenceācounting mechanism explains resource cleanup in multiāprocess environments.
Q4. How does caching file metadata improve performance in BSD UNIX systems?
š Explanation: Caching metadata means the OS can answer queries about a file (size, timestamps, location) from memory instead of reading the inode from disk each time. This reduction in disk I/O accounts for the high cacheāhit rate (ā85āÆ%). The cache does not eliminate all I/O nor affect network speed directly, and permission checks still occur. The benefit is faster fileāsystem operations for applications.
Q5. A program opens a file, reads data, then crashes without explicitly closing the file. What happens to the systemāwide openāfile entry?
š Explanation: When a process ends abruptly, the operating system reclaims its resources, including any open file descriptors. It decrements the open count and, if that count becomes zero, flushes metadata and removes the entry. The entry does not persist indefinitely, and the fileās mode does not change because of the crash. This automatic cleanup prevents resource leaks in a multitasking environment.
Q6. Two processes open the same file. ProcessāÆ1 writes and closes it, while ProcessāÆ2 remains open. When is the fileās metadata flushed to disk?
š Explanation: Metadata is written back only when the last reference to the file is closed, i.e., when the systemāwide open count becomes zero. ProcessāÆ1ās close reduces the count but does not trigger a flush because ProcessāÆ2 still holds the file open. This ensures that any further changes by remaining processes are not lost. Immediate flushing after a write would be inefficient, and caching does not block flushing entirely.
Q7. A network socket is opened using the same openāfile table as regular files. After the socket is closed, which effect occurs on the table?
š Explanation: The unified openāfile table treats sockets like files; closing the socket causes the OS to decrement the open count and, when zero, remove the entry entirely. The entry is not retained as inactive, nor is it transformed into a file record. The table does not grow because of a single socket; it simply reclaims the slot. Understanding this uniform handling clarifies how the OS abstracts diverse resources.
Q8. Why is the file name not required in the perāprocess openāfile table after locating the FCB on disk?
š Explanation: Once the file control block (FCB) is located, it contains all necessary identifiers (inode number, device, etc.) to perform reads, writes, and seeks. The name is only needed for name resolution during the open call; after that, operations use the FCB reference. Storing the name would be redundant and waste memory. This design streamlines perāprocess tables and speeds subsequent file operations.
Q9. A system reports an 85āÆ% cacheāhit rate. If 1,000 file accesses occur, how many disk reads are expected?
š Explanation: With an 85āÆ% hit rate, 15āÆ% of accesses miss the cache. Expected disk reads = 1,000āÆĆāÆ0.15āÆ=āÆ150. OptionāÆA reflects this calculation. OptionsāÆB andāÆC ignore the miss proportion, and optionāÆD assumes perfect caching. Translating hitārate percentages into concrete I/O counts helps students assess performance impact in real workloads.
Q10. What is the primary advantage of using a single mechanism (openāfile table) for files, directories, devices, and network connections?
š Explanation: A unified table lets the OS manage diverse resources with the same data structures and referenceācounting logic, simplifying implementation and reducing bugs. While code size may shrink and permissions still apply, the key benefit is the consistent interface that allows processes to treat sockets, files, and devices similarly. This uniformity is fundamental to modern operatingāsystem design.
Q11. A developer notices frequent open/close cycles for the same file and wants to reduce overhead. Which caching strategy is most effective?
š Explanation: Caching the file descriptor (i.e., reusing the same openāfile entry) avoids repeated lookāups and referenceācount updates, cutting the cost of opening the file repeatedly. Caching data blocks helps read performance but does not eliminate the open/close overhead. Directory entries and process tables are unrelated to this specific inefficiency. Selecting the descriptor cache directly addresses the observed overhead.