πŸŽ“ BookMCQ
← Back to 8. Main Memory

πŸ“ Shared Pages in Paging of Operating System (68 MCQs)

πŸ“– From Operating System β€’ 8. Main Memory β€’ 68 questions available

What is Shared Pages in Paging of Operating System?

Definition:
Shared pages allow multiple processes to map the same physical frame for common code or data reducing memory duplication via identical page table entries.

Example:
Five instances of bash share physical frame F=100F=100 for readline library with each process’s page table pointing to F=100F=100 with read-only permission.

Reason:
Sharing conserves physical memory and improves cache utilization since identical code benefits from spatial locality across processes.

41
Easy
5
Medium
22
Hard

πŸ“ All Shared Pages in Paging of Operating System MCQs

Q1. What fundamental property must code possess to be sharable among multiple processes in a paging environment?

A.It must be dynamically linked
B.It must be reentrant βœ…
C.It must be compiled with position-independent code
D.It must be stored in a shared library
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Reentrant code is non-self-modifying and can be executed concurrently by multiple processes without interference. This property ensures that the shared code remains constant during execution. If the code were self-modifying, one process could alter instructions that another process is currently executing, leading to unpredictable behavior and system crashes. Dynamic linking and position-independent code are useful but not fundamental requirements for sharing pages.

Q2. In a system with 50 users running the same word processor that has 200 KB of reentrant code and 60 KB of non-sharable data per user, what is the total memory saving compared to not sharing the code?

A.3,000 KB
B.10,000 KB
C.12,000 KB
D.9,700 KB βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: Without sharing: 50 users Γ— (200 KB code + 60 KB data) = 13,000 KB. With sharing: 200 KB code + 50 Γ— 60 KB data = 3,200 KB. Saving = 13,000 - 3,200 = 9,800 KB. This demonstrates the significant memory savings achieved through page sharing, which is particularly important in time-sharing systems where many users run identical applications. The data portions remain private because each user has different document content and editing state.

Q3. What critical issue arises if shared code pages are accidentally marked as read-write instead of read-only?

A.The system will run faster due to fewer page faults
B.Multiple processes could corrupt each other's execution βœ…
C.Memory utilization will improve
D.Process context switching will become more efficient
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: If shared code is marked read-write, a bug or malicious process could modify the shared code. Since all processes share the same physical frames for that code, modifications would affect every process using that code. This could cause unpredictable behavior, crashes, or security vulnerabilities. The operating system must enforce read-only protection for shared pages through hardware protection bits. This scenario illustrates why protection mechanisms are crucial for system stability and security.

Q4. A system uses 4 KB pages and has a reentrant library of 28 KB. How many physical frames are required to store this library?

A.7 frames βœ…
B.28 frames
C.8 frames
D.6 frames
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: 28 KB / 4 KB per frame = 7 frames exactly (with no internal fragmentation). If the library were stored as 7 separate pages in logical memory, it would require exactly 7 physical frames in memory. The page table entries for each process would map their virtual pages for the library to these same 7 physical frames. This creates a one-to-one mapping that saves memory because only one copy exists in physical memory regardless of how many processes use the library.

Q5. Why is sharing data pages among processes more challenging than sharing code pages?

A.Data pages are larger than code pages
B.Data pages contain process-specific information that changes during execution βœ…
C.Data pages cannot be mapped to multiple processes
D.The hardware does not support data page sharing
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Data pages contain process-specific state such as variables, stack contents, and heap allocations that vary between processes. Even if processes execute the same program, their data differs based on user input, program state, and execution history. Code pages are constant and therefore naturally sharable. Data sharing requires explicit synchronization mechanisms to maintain consistency, making it more complex than code sharing where processes only read from shared pages.

Q6. In a paging environment, three processes share a reentrant program consisting of 8 pages. Each process has 6 pages of private data. How many total physical page frames are needed?

A.30 frames
B.26 frames
C.24 frames
D.14 frames βœ…
πŸ’‘ Difficulty: hard | βœ… Correct: D

πŸ“– Explanation: Shared code: 8 pages (one copy shared by all processes). Private data: 3 processes Γ— 6 pages = 18 pages. Total = 8 + 18 = 26 frames. Without sharing, we would need 3 Γ— (8 + 6) = 42 frames. The saving is 16 frames. This calculation demonstrates the efficiency of page sharing in multi-user environments. Note that the page table entries for each process would map their logical addresses for the shared code to the same physical frames, while mapping their data pages to different physical frames.

Q7. What would happen to a process if the operating system accidentally swaps out shared code pages that are currently in use by other processes?

A.The process would continue normally
B.Other processes would experience page faults βœ…
C.All processes using the code would be terminated
D.The system would deadlock
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: When shared code pages are swapped out, any process that needs to execute instructions from those pages will encounter page faults. The operating system must bring the pages back into memory to satisfy these faults. This situation demonstrates the importance of reference counting and careful memory management for shared pages. The operating system must track how many processes are using each shared page and only swap it out when no process is actively referencing it.

Q8. If a programmer uses self-modifying code in a program that is intended to be shared, what is the likely outcome?

A.The program will execute faster
B.All processes sharing the program will crash or behave incorrectly βœ…
C.The program will use less memory
D.The operating system will optimize the code
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Self-modifying code modifies its own instructions during execution. If multiple processes share this code, modifications made by one process affect all other processes sharing the same physical pages. This violates the reentrancy requirement and leads to race conditions where process behavior depends on execution ordering. The system may crash or produce incorrect results. This is why self-modifying code is generally discouraged and operating systems enforce protection to prevent modifications to shared pages.

Q9. Which of the following is most likely to be implemented as shared pages in a modern operating system?

A.User document files
B.C standard library functions βœ…
C.User session cookies
D.Process-specific configuration files
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: System libraries like the C standard library contain common functions used by many programs simultaneously. These libraries are compiled as reentrant code and can be shared across processes to save memory. User documents, session cookies, and configuration files contain process-specific data that cannot be shared without synchronization. Libraries such as libc, math libraries, and GUI frameworks are prime candidates for sharing because they are read-only and widely used.

Q10. A system has 4 GB of physical memory and 100 users each running an application with 50 MB of sharable code and 20 MB of private data. What is the minimum physical memory required?

A.7 GB
B.2.5 GB βœ…
C.70 GB
D.2 GB
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Shared code: 50 MB (one copy). Private data: 100 users Γ— 20 MB = 2,000 MB (2 GB). Total = 50 MB + 2,000 MB = 2,050 MB β‰ˆ 2.5 GB. Without sharing: 100 Γ— 70 MB = 7 GB. This exceeds the 4 GB physical memory, but with sharing, all 100 users can run simultaneously. This demonstrates the critical role of page sharing in enabling multi-user systems within memory constraints.

Q11. What is the primary purpose of the valid-invalid bit in page table entries for shared pages?

A.To indicate if the page is currently in the TLB
B.To indicate if the page is in the process's logical address space βœ…
C.To indicate the sharing count of the page
D.To indicate if the page is cached
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The valid-invalid bit indicates whether a page is part of the process's logical address space and thus legally accessible. For shared pages, this bit is set to valid for all processes sharing the page. If a process attempts to access a page that isn't in its address space (invalid bit set), the hardware traps to the operating system. This protection mechanism works identically for shared and non-shared pages. The OS manages this bit to define the boundaries of each process's logical address space.

Q12. How does the operating system maintain consistency when multiple processes share the same physical page?

A.It ensures all processes use the same virtual page number
B.It uses a reference count to track usage
C.It creates a copy of the page for each process
D.It prevents write operations to the page βœ…
πŸ’‘ Difficulty: easy | βœ… Correct: D

πŸ“– Explanation: The operating system marks shared pages as read-only to prevent writes that would affect other processes. While using reference counting to track usage, the primary consistency mechanism is write protection. If a process attempts to write to a shared page (which would be a bug if the code is truly reentrant), the hardware generates a page fault, allowing the OS to handle the violation. This protection ensures that shared pages remain consistent across all processes using them.

Q13. Which of the following best describes the relationship between shared code pages and the logical address spaces of processes sharing them?

A.Each process must map the shared code to the same virtual address
B.Each process can map the shared code to different virtual addresses βœ…
C.The virtual addresses must be contiguous in all processes
D.The virtual addresses must be the same as physical addresses
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The page table maps virtual addresses to physical addresses independently for each process. Processes can map the same physical frames (shared code) to different virtual addresses in their respective logical address spaces. This flexibility is a key advantage of paging. For example, one process might map the shared library at virtual address 0x40000000 while another maps it at 0x50000000. The hardware handles translation through page tables, requiring no specific virtual address alignment between processes.

Q14. Why is shared memory inter-process communication (IPC) often implemented using shared pages?

A.It requires no memory management
B.It provides the fastest communication mechanism βœ…
C.It automatically synchronizes processes
D.It eliminates context switching
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Shared pages allow processes to communicate by reading and writing to the same physical memory frames. This provides the fastest IPC mechanism because data is transferred in memory without any copying operations. Unlike pipes or message queues, shared memory avoids system call overhead for each data transfer. However, processes must implement their own synchronization mechanisms. The OS simply manages the page table mappings to share the physical pages between processes.

Q15. If a process has a page table entry for shared code with the valid bit set to 0, what would happen?

A.The process would receive a segmentation fault βœ…
B.The process would use the page from the TLB
C.The process would continue without using the page
D.The process would automatically load the page
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: When the valid bit is 0, the page is not considered part of the process's logical address space. Any access attempt generates a trap to the operating system, typically resulting in a segmentation fault or page fault exception. The process cannot execute instructions from that virtual address. For shared code, this situation might occur if the OS hasn't properly set up the page table or if there was a bug in the process initialization code.

Q16. A reentrant subroutine is used by 20 processes. If the subroutine consists of 12 pages and private data per process is 8 pages, what is the total number of physical frames used when all processes are active?

A.240 frames
B.28 frames βœ…
C.20 frames
D.160 frames
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Shared code: 12 frames (one copy). Private data: 20 processes Γ— 8 pages = 160 frames. Total = 12 + 160 = 172 frames. Without sharing: 20 Γ— (12 + 8) = 400 frames. Saving = 228 frames. This demonstrates how sharing code significantly reduces memory usage, allowing many more processes to be active simultaneously. The OS manages the physical frames through the frame table, keeping track of which frames contain shared code.

Q17. Which of the following is a potential drawback of using shared pages?

A.Increased memory usage
B.Complexity in page table management βœ…
C.Slower program execution
D.Reduced multiprogramming level
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Sharing introduces complexity in page table management. The OS must maintain reference counts to know when a shared page can be freed, ensure consistent mappings across processes, handle protection violations, and manage TLB entries for shared pages. While sharing reduces memory usage and improves multiprogramming, it requires additional OS data structures and careful coordination. The performance impact is typically small compared to the memory benefits, but the implementation complexity is higher than non-shared pages.

Q18. What role does the translation look-aside buffer (TLB) play in the performance of shared pages?

A.It stores shared pages in hardware
B.It speeds up address translation for frequently accessed pages βœ…
C.It prevents sharing violations
D.It manages the reference count of shared pages
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The TLB caches recent address translations, including those for shared pages. When a process accesses shared code, the virtual-to-physical address translation is cached in the TLB after the first access. This significantly speeds up subsequent accesses because the hardware can translate the address without consulting the page table in memory. The TLB operates identically for shared and non-shared pages, providing the same performance benefit. However, context switches may flush the TLB, requiring translations to be reloaded.

Q19. How would the operating system know when it is safe to free a shared page frame?

A.It would free the page when memory is low
B.It would free the page when a process terminates
C.It would free the page when the reference count reaches zero βœ…
D.It would free the page after a time-out
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The OS maintains a reference count for each shared page. Every time a new process maps to the page, the count is incremented. When a process unmaps the page, the count is decremented. The page can only be freed when the reference count reaches zero, indicating no process is using it. This prevents premature freeing that would cause page faults for active processes. Reference counting is a standard technique in resource management to track shared resource usage.

Q20. If two processes share a page and both have write permission due to an OS bug, what is the most likely consequence?

A.The system will save memory
B.The system will operate correctly
C.Data corruption in one or both processes βœ…
D.The processes will be terminated
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: Write permission on a shared page means either process can modify its contents. Since both processes expect their own private data but are actually sharing the same physical frame, writes from one process will overwrite data used by the other process. This leads to data corruption and unpredictable behavior. The OS must enforce read-only access for shared code pages. This example illustrates why protection is critical for sharing and why the OS must carefully manage page table permissions.

Q21. What is a key advantage of sharing pages over loading separate copies of code?

A.Faster program loading
B.Better processor cache utilization
C.Reduced disk I/O and memory usage βœ…
D.Simpler memory management
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Shared pages significantly reduce disk I/O and memory usage. Instead of loading the same code from disk for each process (which would require multiple disk reads and memory allocation), the OS loads the code once into physical memory and maps it into multiple logical address spaces. This reduces disk access time, saves physical memory, and allows more processes to run concurrently. The time to create a new process is also reduced because shared code doesn't need to be loaded from disk.

Q22. A system has a page size of 2 KB and a shared library of 15 KB. What is the internal fragmentation when storing this library?

A.0 KB
B.1 KB βœ…
C.2 KB
D.3 KB
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: 15 KB / 2 KB per page = 7.5 pages, so 8 pages are needed (rounded up). Total allocated space = 8 Γ— 2 KB = 16 KB. Internal fragmentation = 16 KB - 15 KB = 1 KB. This shows that even shared pages incur internal fragmentation when the library size doesn't exactly match page boundaries. While page sharing saves memory compared to multiple copies, it doesn't eliminate the overhead of page-based allocation. This fragmentation is typically acceptable given the overall memory savings from sharing.

Q23. Why must shared code be reentrant?

A.To reduce the number of page faults
B.To allow multiple processes to execute it simultaneously without conflict βœ…
C.To prevent the code from being swapped to disk
D.To enable caching of the code in the TLB
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Reentrant code can be executed simultaneously by multiple processes because it doesn't modify itself during execution. This is essential for sharing because processes execute code interleaved in time on the CPU. If the code were self-modifying, one process's modifications could affect another's execution, causing errors. Reentrancy ensures the code behaves identically regardless of which process executes it, making it safe to share across processes. This property is fundamental to code sharing in paging systems.

Q24. In a heavily used time-sharing system, what would be the impact of disabling page sharing?

A.Increased security
B.Decreased memory usage
C.Increased response time for users βœ…
D.Faster context switching
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Disabling page sharing would require loading separate copies of common programs for each user. This would dramatically increase memory usage, forcing the system to swap processes more frequently. Increased swapping would significantly degrade response times as processes wait for I/O operations. The system might be unable to support the same number of concurrent users. This illustrates why sharing is essential for time-sharing system performance and why modern operating systems rely heavily on shared pages.

Q25. How can shared pages be used to implement copy-on-write (COW) optimization?

A.By sharing pages until a write occurs, then creating a copy βœ…
B.By creating a copy of the page for each process immediately
C.By preventing any writes to shared pages
D.By writing to the page and then sharing it
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Copy-on-write allows processes to share pages while maintaining the illusion of private memory. Initially, processes share a page with read-only permissions. When a process attempts to write, a page fault occurs, and the OS creates a private copy of the page for that process while leaving the original shared with others. This combines sharing benefits with private memory semantics. COW is widely used in process creation (fork() system call) where parent and child processes initially share pages until one writes to them.

Q26. What happens to the TLB when a process that shares pages with others is context-switched out?

A.All TLB entries are invalidated βœ…
B.TLB entries for shared pages remain valid
C.The TLB is unaffected
D.The shared pages are removed from the TLB
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: When a context switch occurs, the TLB must be flushed (or ASID-based protection used) to prevent the new process from using address translations from the previous process. This happens regardless of whether pages are shared. Even though shared physical frames could be valid across processes, the virtual-to-physical mappings differ, and the TLB contains virtual addresses. Without ASIDs, flushing is necessary for correctness. This contributes to context-switch overhead but is an accepted cost of paging systems.

Q27. Why are shared libraries often mapped into the same virtual address range across processes?

A.It reduces memory usage
B.It improves TLB performance and reduces context-switch overhead βœ…
C.It simplifies process creation
D.It prevents fragmentation
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: When shared libraries are mapped to the same virtual addresses across processes, the TLB entries remain valid across context switches because the translations are consistent. This improves TLB hit rates and reduces the overhead of context switching. Without ASIDs, this technique helps retain TLB entries. If virtual addresses differ, the TLB must be flushed more frequently. While memory usage remains the same, performance is enhanced by reducing translation misses.

Q28. A programmer wants to share a large data structure across multiple processes to implement collaboration. What mechanism would the operating system provide?

A.Shared memory via shared pages βœ…
B.File I/O
C.Named pipes
D.Message passing
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: The OS provides shared memory as a mechanism for sharing data pages across processes. This uses the same paging infrastructure that supports code sharing. Processes can map the same physical frames for data pages into their address spaces. However, unlike code sharing where pages are read-only, shared data pages require synchronization mechanisms (semaphores, mutexes) to prevent race conditions. This is a powerful IPC mechanism used in many applications for efficient data sharing.

Q29. What protection is required for shared code pages?

A.Read-only βœ…
B.Read-write
C.Execute-only
D.Any combination is acceptable
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Shared code must be read-only to prevent modifications that would affect other processes. This protection is enforced by the hardware through page table permission bits. If a process attempts to write to a read-only page, the hardware traps to the OS. This protection ensures shared code remains invariant. Execute permission is also typically set so processes can execute instructions from these pages. The combination is usually read-only and execute-only, not read-write.

Q30. What is the effect of page sharing on system security?

A.It eliminates all security risks
B.It requires careful protection to prevent unauthorized access βœ…
C.It automatically enhances security
D.It makes systems more vulnerable
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Page sharing requires careful security management. While sharing can expose information if pages are incorrectly mapped between processes, the hardware protection bits prevent unauthorized writes. The OS must ensure that page tables are correctly configured and that processes cannot access pages they shouldn't. Shared libraries are safe because they contain no process-specific data. However, shared memory for IPC requires explicit permission and synchronization to maintain security and correctness.

Q31. A process shares code pages with 10 other processes. When this process terminates, what must the operating system do?

A.Free all its frames immediately
B.Only free its private data frames; keep shared code if reference count > 0 βœ…
C.Force all processes to terminate
D.Free the shared code frames
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The OS decrements the reference count for shared pages. Since other processes still use the shared code, the frames remain allocated. Only the process's private data frames are freed. The page table entries for the terminated process are removed. This demonstrates reference counting: pages remain until the last process using them terminates. This careful management ensures shared pages aren't prematurely freed while allowing proper cleanup when no processes need them.

Q32. How would a distributed system implement page sharing across different machines?

A.It cannot, as pages exist only on a single machine
B.Through network file systems or distributed shared memory βœ…
C.By copying the pages to each machine
D.By using virtual machine migration
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Distributed shared memory (DSM) extends page sharing across multiple machines in a network. Pages can be shared by mapping them into the address spaces of processes on different computers. The system maintains consistency using protocols like invalidate or update-based approaches. Network file systems can also provide shared access to files but at a higher level than pages. DSM is complex due to network latency and consistency requirements but enables large-scale sharing across distributed systems.

Q33. What happens if a shared code page is located at virtual address 0x1000 in process A and 0x2000 in process B?

A.The system will crash
B.Address translation remains correct through page tables βœ…
C.The page cannot be shared
D.One process must change its virtual address
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Page tables handle different virtual-to-physical mappings independently. Process A's page table maps virtual 0x1000 to physical frame X, and Process B's maps virtual 0x2000 to the same physical frame X. The hardware uses each process's page table for address translation. This is perfectly valid and demonstrates the flexibility of paging. The virtual addresses don't need to match because the MMU performs translation. This independence is one of the key advantages of paging over segmentation.

Q34. Why would an OS use shared pages for read-only data like font files in a graphical system?

A.To reduce the number of open file handles
B.To eliminate redundant copies in memory βœ…
C.To speed up context switches
D.To simplify the driver code
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Multiple applications use the same fonts in graphical environments. By storing font files as shared read-only pages, the OS loads them once into physical memory and maps them to all applications needing those fonts. This prevents redundant memory usage and reduces disk I/O. The technique is similar to shared libraries and demonstrates how sharing applies to various types of read-only data. It improves system performance, especially in environments with many graphical applications.

Q35. What is the relationship between internal fragmentation and shared pages?

A.Sharing eliminates internal fragmentation
B.Shared pages still suffer from internal fragmentation βœ…
C.Internal fragmentation prevents sharing
D.Fragmentation only affects private pages
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Shared pages are still subject to internal fragmentation because pages are allocated in fixed-size frames. If a shared library size doesn't match the page size, the last frame is partially filled regardless of sharing. However, the amount of wasted memory is the same whether the page is shared or private. The benefit of sharing is that this fragmentation occurs once per shared entity rather than once per process. Thus, sharing reduces the impact of internal fragmentation by amortizing it across all users.

Q36. If two processes share a page and one process has write permission due to a security vulnerability, what is the potential risk?

A.Memory corruption and information disclosure βœ…
B.No risk, as writes are harmless
C.The process would crash immediately
D.Only the writing process would be affected
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: Write permission on a shared page allows unauthorized modifications that affect all processes sharing the page. This could corrupt program behavior, crash applications, or be exploited to gain unauthorized access. A malicious process could modify shared library code to redirect execution to malicious routines. This is why the OS must strictly enforce protection bits. Such vulnerabilities highlight the critical importance of proper access control in shared page implementations.

Q37. What is the advantage of using ASIDs (Address Space Identifiers) in systems with extensive page sharing?

A.It reduces the need to flush the TLB during context switches βœ…
B.It allows more shared pages
C.It increases memory protection
D.It simplifies page table management
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: ASIDs allow the TLB to hold entries from multiple processes simultaneously. When a context switch occurs, entries with the new process's ASID remain valid, while entries from other processes are distinguished by their ASIDs. This avoids flushing the TLB, improving performance in systems with frequent context switches. For shared pages, ASIDs can still distinguish between processes, but the physical frames are shared. This combined approach maintains TLB efficiency while supporting sharing.

Q38. What would be the consequence of a shared library being updated to a new version?

A.All processes using it must be restarted
B.Processes continue using the old version; new processes use the new version βœ…
C.The system would crash
D.All processes would automatically use the new version
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: With dynamic linking and versioning, shared libraries can be updated without restarting running processes. The library file is replaced on disk. New processes load the new version, while existing processes continue using the version they already have in memory (if reference counting prevents freeing). This demonstrates the flexibility of shared libraries and why version information is important. The OS must manage multiple versions simultaneously until all processes using the old version terminate.

Q39. Which of the following statements best describes reentrant code?

A.It can be written to safely
B.It can be executed simultaneously by multiple processes without conflict βœ…
C.It must be stored in a special memory region
D.It cannot contain any function calls
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Reentrant code is non-self-modifying and uses only local stack variables or read-only data. It can be safely interrupted and executed again before completion. Multiple processes can execute reentrant code interleaved without interference because each process maintains its own registers and stack. This property makes code sharable because the code itself remains constant while the execution state is maintained separately for each process. Reentrancy is essential for sharing code pages in multiprogrammed systems.

Q40. A system uses 8 KB pages and has a shared library of 35 KB. How much memory is wasted to internal fragmentation when this library is stored in memory?

A.1 KB
B.3 KB
C.5 KB βœ…
D.7 KB
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: 35 KB / 8 KB = 4.375 pages, so 5 pages needed. Allocated = 5 Γ— 8 KB = 40 KB. Wasted = 40 KB - 35 KB = 5 KB. This internal fragmentation occurs once for the shared library, not for each process. If this library were loaded separately for 100 processes, the waste would be 500 KB. Sharing reduces total fragmentation, demonstrating another benefit of page sharing. The cost of fragmentation is amortized across all processes using the library.

Q41. How does the operating system know which shared pages are in the TLB for a given process?

A.It maintains a TLB table per process
B.It doesn't track TLB contents explicitly βœ…
C.It stores this information in the page table
D.It uses the frame table to track TLB entries
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The OS generally does not track TLB contents because the TLB is a hardware-managed cache. The CPU hardware handles TLB lookups, misses, and replacements. The OS only sets up page tables; the hardware uses them to populate the TLB transparently. The OS may invalidate TLB entries when needed (e.g., during context switches or page table changes), but it doesn't know which entries are present at any given time. This separation of concerns keeps memory management efficient and hardware-independent.

Q42. What is the primary reason for avoiding self-modifying code in shared libraries?

A.It makes debugging more difficult
B.It prevents sharing because modifications would affect all processes βœ…
C.Self-modifying code is slower
D.It requires more memory
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Self-modifying code changes its own instructions during execution. If shared, modifications made by one process would change the code that other processes are executing. This violates the fundamental principle of sharing: that the shared resource should be invariant. Even if modification is intentional, the effects would be unpredictable and process-dependent. This is why shared libraries must be read-only and reentrant. Self-modifying code is rarely used today except in specific applications where code generation or optimization is needed.

Q43. A shared library of 12 pages is used by processes A and B. Process A also has 5 pages of private data, and Process B has 7 pages. How many physical frames are used?

A.24 frames
B.19 frames βœ…
C.12 frames
D.19 frames
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Shared library: 12 frames. Private data A: 5 frames. Private data B: 7 frames. Total = 12 + 5 + 7 = 24 frames. This demonstrates how sharing reduces total memory usage. Without sharing: (12 + 5) + (12 + 7) = 36 frames. Saving = 12 frames. The frame table would show 12 frames marked as shared with reference count 2, while the remaining frames are allocated to specific processes. This efficient management allows more processes to run concurrently.

Q44. What would be an appropriate use of shared pages for communication between processes?

A.To share an array of sensor data that multiple processes read βœ…
B.To share a program's source code
C.To share process-specific stack contents
D.To share file directory structures
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Shared memory pages can be used for inter-process communication when processes need to share and exchange data. Sensor data that multiple processes read is ideal because it's read-mostly and accessed frequently. Shared memory provides fast access without copying. However, processes must synchronize access to prevent races. Shared pages are less suitable for stack contents (process-private), source code (file-based rather than memory-based), or directory structures (kernel-managed).

Q45. How would page sharing affect the implementation of a copy-on-write (COW) fork in a multi-threaded process?

A.Threads would see inconsistent memory
B.COW works normally as threads share the address space βœ…
C.COW cannot work with threads
D.Threads would cause excessive page faults
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: In fork, the parent and child initially share pages with COW protection. Within a process, all threads share the address space, so COW semantics are consistent across threads. When one thread writes to a shared page after fork, the OS creates a private copy for that process (affecting all its threads). The implementation remains correct because threads share page tables. This demonstrates how page sharing mechanisms integrate with threading and COW to provide efficient process creation while maintaining memory isolation.

Q46. What is the impact of shared pages on page table sizes?

A.Sharing reduces the total number of page table entries
B.Page table sizes remain the same per process βœ…
C.Sharing increases page table sizes due to reference counts
D.Sharing eliminates the need for page tables
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Each process still requires a full page table mapping its entire logical address space, including shared pages. The page table entries for shared pages point to the same physical frame numbers. While sharing doesn't reduce page table sizes, it reduces physical memory usage. The OS must store reference count information separately (in the frame table or auxiliary data structures). Therefore, sharing primarily saves physical frames, not page table space.

Q47. Can two processes share a page that is writable by both, and if so, what precautions must be taken?

A.Yes, if the processes use semaphores to coordinate writes βœ…
B.No, writable pages cannot be shared
C.Yes, without any precautions
D.Yes, if the page is marked as temporary
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Two processes can share a writable page, typically for shared memory IPC, but must use synchronization mechanisms like semaphores or mutexes to prevent race conditions. Without coordination, writes from one process could interleave with writes from another, corrupting data. This is different from shared code, which is read-only. The OS allows writable shared pages when explicitly requested, but processes are responsible for ensuring correct access. This reflects the trade-off between performance and complexity in inter-process communication.

Q48. A page is shared by 5 processes. When one process terminates, what happens to the reference count?

A.It is decremented by 1 βœ…
B.It becomes 0
C.It remains the same
D.It is incremented by 1
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: When a process terminates, the OS decrements the reference count of all pages it was using, including shared pages. If the count becomes 0, the shared page can be freed. If it's greater than 0, the page remains allocated. For example, a page shared by 5 processes has a count of 5. When one terminates, the count decreases to 4, and the page stays because other processes still need it. This reference counting is essential for proper memory management in sharing systems.

Q49. How would implementing shared pages impact system boot time?

A.Boot time would significantly increase
B.Boot time would remain similar as shared pages are established after boot βœ…
C.Boot time would decrease
D.No impact on boot time
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Page sharing typically doesn't affect boot time significantly. Shared pages are established as processes start and request memory mapping. The boot process itself involves loading the kernel and basic system services, which may have some shared components. However, most sharing occurs after boot when applications start. The impact on boot time is minimal compared to other boot activities like hardware initialization and filesystem mounting. The OS sharing infrastructure is initialized early but doesn't require extensive setup.

Q50. Why would an operating system choose not to allow sharing of all read-only code pages?

A.Sharing cannot be implemented for code
B.Protection and performance trade-offs βœ…
C.Hardware limitations
D.Security concerns with shared code
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: While sharing read-only code pages is generally beneficial, there are trade-offs. The OS must manage reference counts, ensure TLB consistency, and handle protection correctly. Sharing also requires careful virtual memory management. In some cases, the overhead of managing shared pages might outweigh the memory benefits, especially for small code segments or systems with limited multiprogramming. Additionally, some systems may prioritize isolation over sharing for security or simplicity reasons.

Q51. A process forks a child. If both parent and child share code pages, what happens when the parent modifies a page that is supposed to be shared?

A.The child will also see the modification
B.The operating system will create a copy of the page for the parent βœ…
C.The page becomes read-only for both
D.The modification fails with an error
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: In most systems, when a process attempts to modify a shared page (especially after fork), the OS uses copy-on-write. The parent receives a private copy of the page, and the modification affects only the parent. The original shared page remains unchanged and continues to be shared with the child. This ensures that modifications don't affect other processes while maintaining sharing for unmodified pages. This is a key optimization in modern operating systems.

Q52. What is the advantage of using system libraries as shared pages?

A.Libraries can be updated without affecting running processes βœ…
B.Libraries execute faster
C.Libraries require less code
D.Libraries use more memory
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: When system libraries are implemented as shared pages, they can be updated on disk without affecting currently running processes that are using old versions in memory. New processes will load the updated version. This allows system maintenance without restarting applications. Additionally, sharing saves memory and improves cache locality. The versioning mechanism ensures processes continue using the version they were compiled with. This flexibility is a major advantage of dynamic linking with shared libraries.

Q53. In an embedded system with limited memory, why might page sharing be particularly valuable?

A.It reduces the amount of code that must be stored in ROM
B.It allows multiple applications to share the same code in flash memory βœ…
C.It speeds up processor execution
D.It eliminates the need for a file system
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Embedded systems often have limited RAM but can use shared pages to run multiple applications from the same code stored in flash or ROM. This reduces RAM usage by loading code once and mapping it to multiple processes. This is especially useful in systems with many similar tasks. The memory savings allow more applications to run simultaneously or reduce hardware costs. Page sharing is thus a critical technique for resource-constrained embedded systems.

Q54. How would a system with no support for page sharing handle 100 users running the same editor?

A.It would swap processes efficiently
B.It would load the editor separately for each user, consuming more memory βœ…
C.It would use segmentation instead
D.It would crash due to memory exhaustion
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Without page sharing, the OS would load a separate copy of the editor's code for each user. For 100 users, if the editor is 50 KB, memory usage would be 100 Γ— 50 KB = 5 MB just for code. With sharing, only 50 KB is needed. This demonstrates why sharing is essential for multi-user systems. The increased memory usage would likely cause the system to page heavily or be unable to support many users. This illustrates the importance of sharing in enabling efficient multi-user environments.

Q55. Which of the following scenarios best illustrates the effective use of shared pages in a modern operating system?

A.A database management system with private data caches
B.A GUI environment where all applications use the same font rendering library βœ…
C.A web browser storing individual user session data
D.A text editor maintaining per-user configuration
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: GUI environments benefit significantly from shared pages because many applications use the same system libraries for window management, font rendering, and graphics. These libraries are read-only and can be shared, reducing memory usage. In contrast, database caches, user sessions, and configurations contain process-specific data that cannot be shared. This scenario illustrates how sharing applies to common read-only resources that many processes need simultaneously.

Q56. Why might a programmer avoid using shared memory pages for large data structures when the system has a low number of processes?

A.Shared memory is always slower
B.The overhead of sharing outweighs the memory benefits βœ…
C.Shared memory is not available
D.Shared memory causes data corruption
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: When only a few processes use shared memory, the overhead of setting up and managing shared pages (creating mappings, handling synchronization, reference counting) may not be justified. For example, with only two processes, copying data between them might be simpler and more maintainable than complex shared memory management. The memory savings are minimal, but implementation complexity increases. This trade-off explains why sharing isn't universally beneficial and must be evaluated based on system conditions.

Q57. In a 64-bit system with a huge address space, does page sharing become less important?

A.Yes, because memory is abundant
B.No, because physical memory is still limited βœ…
C.Yes, because address space is unlimited
D.No, because sharing affects performance, not just memory usage
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Even with 64-bit virtual address spaces, physical memory remains a finite resource. Page sharing still saves physical memory, allowing more pages to be cached or more processes to run. While virtual address space is abundant, physical memory capacity is limited by hardware cost and technology. Sharing remains important for performance and efficiency regardless of address space size. The virtual address space size doesn't affect the need to conserve physical memory through sharing.

Q58. What is the relationship between shared pages and the global descriptor table in segmentation systems?

A.Shared pages eliminate the need for segmentation
B.Segmentation can still be used with shared pages βœ…
C.Shared pages require segmentation
D.Shared pages replace segment descriptors
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Page sharing and segmentation can coexist. In systems that support both, shared pages may still be used within segments. The global descriptor table (GDT) defines segment boundaries and protection, while paging provides page-level sharing. These are orthogonal memory management techniques. Programs can share code across processes at the page level while still using segments for protection and organization. This combination is used in systems like x86 where segmentation and paging both exist.

Q59. What would happen if a shared library page is modified in memory by a hardware error (e.g., cosmic ray strike)?

A.All processes using it would experience random errors βœ…
B.The OS would crash
C.The page would be automatically repaired
D.The processes would continue normally
πŸ’‘ Difficulty: medium | βœ… Correct: A

πŸ“– Explanation: A hardware error corrupting a shared page would affect all processes using that page because they share the same physical frame. This could cause data corruption, crashes, or incorrect behavior in multiple applications simultaneously. Without ECC (Error Correcting Code) memory, the corruption would propagate to all users of the shared code. This demonstrates a disadvantage of sharing: errors in shared resources have a broad impact compared to private pages where only one process is affected. High-availability systems often use ECC memory to mitigate this risk.

Q60. How would a security-conscious system design handle shared pages to prevent information leaks?

A.It would only allow sharing of immutable pages βœ…
B.It would always create private copies
C.It would not allow sharing at all
D.It would use encryption for shared pages
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: To prevent information leaks, shared pages should be immutable (read-only). Writable shared pages could be used to leak information between processes if not properly synchronized. Many secure systems restrict sharing to read-only code and data, requiring explicit permission and careful synchronization for writable shared memory. This approach minimizes the attack surface while still providing memory efficiency benefits. The OS must enforce strict protection and validate any sharing requests to maintain security.

Q61. Consider a scenario where a shared library version changes from 2.1 to 2.2 with minor bug fixes. Which processes will use the new version?

A.Only newly started processes that link to version 2.2 βœ…
B.All processes will immediately use 2.2
C.Processes using 2.1 must be restarted
D.The system will use both versions
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: When a shared library is updated with minor changes (same major version number), existing processes continue using the version they already have loaded in memory. New processes will load the updated version. This allows system updates without disrupting running applications. The OS maintains multiple copies of the library in memory (one for each version in use). This demonstrates the versioning mechanism that makes shared libraries practical for system maintenance.

Q62. What is the effect of page sharing on the I/O performance when loading applications?

A.I/O performance worsens due to shared pages
B.I/O improves because shared pages reduce disk reads βœ…
C.I/O performance remains unchanged
D.Shared pages require more I/O
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: When shared pages are used, the OS loads the shared code once from disk. Subsequent processes mapping the same code don't need additional disk I/O because the code is already in memory. This significantly reduces disk reads, improving application loading times. This is particularly beneficial for frequently used libraries and applications. The initial loading cost is amortized across all processes using the shared code, making system operation more efficient overall.

Q63. How would a memory leak in a shared library affect the system compared to a leak in private code?

A.It would affect only the process that caused the leak
B.It would affect all processes using the library βœ…
C.It would not affect any processes
D.It would crash the system immediately
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: A memory leak in a shared library would affect all processes using it because the leaked memory isn't reclaimed while any process holds a reference. This could cause gradual memory depletion across the entire system as more processes use the library. In contrast, a leak in private code only affects that specific process and is cleaned up when the process terminates. This illustrates that bugs in shared code can have broader system impact, emphasizing the importance of careful resource management in shared libraries.

Q64. Why might page sharing not be beneficial in a system with very few processes?

A.Because sharing overhead exceeds memory savings βœ…
B.Because the OS doesn't support sharing
C.Because processes have no shared code
D.Because pages are too small
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: With very few processes, the memory savings from sharing are minimal (e.g., saving 1 MB of code for 2 processes). However, the overhead includes maintaining reference counts, managing shared page tables, ensuring consistency, and handling protection. This overhead might outweigh the savings, making sharing less beneficial. In such cases, simpler memory management without sharing might be more efficient. This illustrates that memory management techniques should be evaluated in context, not always applied universally.

Q65. What is the primary challenge in implementing shared pages for libraries that use global variables?

A.Global variables cannot be shared
B.Global variables would become inconsistent across processes βœ…
C.Global variables cause page faults
D.Global variables increase memory usage
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Global variables in libraries typically represent shared state that would be inconsistent if multiple processes share the same physical pages. Each process expects its own copy of global data. This is why library code is separated from library data. The code is shared (read-only), while data pages are private to each process. If a library uses global variables, these must be in private data pages. This architectural separation is essential for correct sharing.

Q66. How does the use of shared pages affect system reliability?

A.It reduces reliability due to shared vulnerabilities βœ…
B.It increases reliability through code verification
C.It doesn't affect reliability
D.It makes the system more reliable
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Shared pages can reduce reliability because a bug in shared code affects all processes using it, rather than just one process. Similarly, a security vulnerability in a shared library exposes all processes to that risk. This is a disadvantage of sharing. However, thorough testing of shared code benefits all users, potentially improving reliability. This trade-off between efficiency and fault isolation is a fundamental consideration in system design. Protected execution environments and robust testing help mitigate these risks.

Q67. Why would a real-time system limit the use of page sharing?

A.Sharing reduces performance predictability βœ…
B.Sharing requires too much memory
C.Real-time systems don't need memory management
D.Sharing cannot be implemented in real-time systems
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Real-time systems require predictable execution times. Page sharing can introduce variability through shared page access patterns, TLB effects, and reference count management. Additionally, page faults or TLB misses in shared pages might affect timing more unpredictably. To maintain deterministic behavior, real-time systems may prefer private memory mappings or avoid sharing. This illustrates how system requirements influence memory management strategy selection.

Q68. What is the impact of shared pages on the effectiveness of processor caches?

A.They improve cache utilization βœ…
B.They hurt cache performance
C.They have no impact
D.They depend on the cache architecture
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: Shared pages can improve cache utilization because frequently used code is stored in one physical location. When multiple processes use shared code, the cache lines holding that code benefit from temporal locality across processes. This increases cache hit rates and improves performance. However, if processes with different access patterns share pages, it could cause cache conflicts. Overall, well-designed shared page usage generally enhances cache efficiency through code reuse.

πŸ”— Related Topics (MCQs)