๐ŸŽ“ BookMCQ
โ† Back to 8. Main Memory

๐Ÿ“ Standard swapping in main memory (15 MCQs)

๐Ÿ“– From Operating System โ€ข 8. Main Memory โ€ข 15 questions available

What is Standard swapping in main memory?

Definition:
Swapping moves entire processes between main memory and secondary storage (backing store) to free RAM for other processes when memory is overcommitted.

Example:
An idle process occupying 256ย MB256 \text{ MB} is swapped out to disk and later swapped back in when the user resumes interaction restoring its complete state.

Reason:
Swapping enables degree of multiprogramming beyond physical memory limits though context switch overhead increases due to full process transfer.

3
Easy
7
Medium
5
Hard

๐Ÿ“ All Standard swapping in main memory MCQs

Q1. A user program requests to load its code into memory. Which action performed by the operating system guarantees that the program cannot modify the OS code or other users' memory?

A.Load base and limit registers using a privileged instruction โœ…
B.Allow the program to set its own base register
C.Disable paging
D.Run the program in user mode without checks
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– Explanation: The operating system uses a privileged instruction that can only run in kernel mode to load the base and limit registers. Because only the OS can execute privileged instructions, a user program cannot change these registers, preventing it from accessing or altering memory belonging to the OS or other users. Options B, C, and D either give the user too much control or remove protection, so they would not stop unauthorized modification.

Q2. What is the primary purpose of the base register in a protected memory system?

A.Store the size of the process
B.Hold the starting physical address of a process's address space โœ…
C.Indicate the current instruction pointer
D.Keep track of I/O device status
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– Explanation: The base register contains the physical address where a process's logical address space begins. By adding the base value to a logical address, the hardware translates it to a real memory location. This ensures each process accesses only its own allocated region. The other options describe unrelated functions: size is managed by the limit register, the instruction pointer tracks execution, and I/O status is handled by separate registers.

Q3. Why can only the operating system modify the contents of base and limit registers?

A.Because they are stored in readโ€‘only memory
B.Because modifying them requires a privileged instruction executable only in kernel mode โœ…
C.Because user programs lack arithmetic capability
D.Because the registers are physically inaccessible to user code
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– Explanation: Base and limit registers are changed only through a privileged instruction, which the CPU permits when running in kernel (supervisor) mode. User programs execute in user mode and cannot invoke privileged instructions, so they cannot alter these registers. This restriction keeps user code from expanding its address space or bypassing protection. The other choices are incorrect: the registers are not readโ€‘only, arithmetic ability is unrelated, and physical inaccessibility is not the enforcement mechanism.

Q4. A process has base register = 3000 and limit register = 1200. The process generates a logical address 4250. Which outcome will occur?

A.The address is translated to 4250 and accessed
B.The address triggers a trap because it exceeds the limit
C.The address is wrapped around to 250 โœ…
D.The OS silently adjusts the limit
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– Explanation: The logical address 4250 is compared to the limit value 1200. Since 4250โ€ฏ>โ€ฏ1200, the address exceeds the allowed range, causing the hardware to raise a protection fault (trap) and transfer control to the operating system. The OS can then handle the error, typically terminating the offending process. Options A and D incorrectly assume the address is permitted, and option C suggests an undefined wrapโ€‘around behavior that does not exist in base/limit protection.

Q5. How does adding a base register to a logical address implement address translation?

A.It replaces the logical address with the base value
B.It shifts the logical address by the limit amount
C.It adds the base to the logical address to produce a physical address
D.It encrypts the address for security โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– Explanation: When a process generates a logical address, the hardware adds the value stored in the base register to this address, yielding the corresponding physical address in main memory. This simple arithmetic provides isolation because each process can have a different base value. Options A and B describe unrelated operations, and option D introduces encryption, which is not part of base/limit translation.

Q6. During a context switch on a multiprocessor, the OS must save the current process's registers to memory. Which register must be stored before loading the next process's base register?

A.Program Counter
B.Base Register
C.Limit Register
D.All of the above โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– Explanation: A complete context switch requires preserving the program counter (to know where to resume), the base register (to retain the current address space), and the limit register (to keep the protection bounds). Saving all three ensures that when the next process is loaded, its own base and limit can be installed without losing the previous process's state. Any answer that omits one of these registers would risk incorrect execution after the switch.

Q7. A user program attempts to write to address 8500 while its limit register is 8000. What will the hardware do?

A.Allow the write
B.Raise a protection fault and transfer control to the OS
C.Ignore the write
D.Automatically increase the limit register โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– Explanation: The hardware compares the requested address with the limit value. Because 8500โ€ฏ>โ€ฏ8000, the access violates the defined bounds, so the CPU generates a protection fault (trap) and passes control to the operating system. The OS can then terminate the program or take corrective action. Options A and C incorrectly assume the hardware permits the outโ€‘ofโ€‘range operation, and option D suggests automatic limit expansion, which is not part of base/limit protection.

Q8. Compared to segmentation, what is a key advantage of using simple base and limit registers for protection?

A.They support variableโ€‘size segments
B.They require fewer hardware checks per memory reference
C.They allow overlapping address spaces โœ…
D.They enable dynamic code loading
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– Explanation: Base and limit registers perform a single bound check for each memory reference, making the hardware logic simpler and faster than the multiple checks often needed in segmented schemes. This reduction in complexity speeds up address translation. Options A and D describe capabilities of more sophisticated schemes, while option C is not a typical advantage of simple base/limit protection.

Q9. Two processes, P1 and P2, need to share a readโ€‘only data region located at physical addresses 15000โ€“15999. The OS sets base registers to 15000 for both and limit registers to 1000. Which additional configuration ensures P2 cannot write to this region while P1 can?

A.Set P2โ€™s limit to 0
B.Use a separate writeโ€‘protect bit in P2โ€™s page table entry โœ…
C.Load P2 in user mode with a readโ€‘only flag
D.Enable a hardware writeโ€‘protect bit for P2โ€™s segment
๐Ÿ’ก Difficulty: hard | โœ… Correct: B

๐Ÿ“– Explanation: Base and limit registers only enforce address bounds, not readโ€‘only versus readโ€‘write permissions. To prevent P2 from writing, the OS must run P2 with a readโ€‘only privilege flag (or similar protection mode) so that any write attempt to the shared region triggers a fault. Options A and D either remove access entirely or rely on hardware features not described, while option B refers to paging, which is outside the simple base/limit model.

Q10. Why are base and limit registers insufficient by themselves to prevent bufferโ€‘overflow attacks that overwrite adjacent data structures?

A.Because they only check address bounds, not the logical structure of data โœ…
B.Because they can be altered by user programs
C.Because they automatically expand limits when overflow occurs
D.Because they encrypt memory contents
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– Explanation: Base and limit registers guarantee that a program cannot access memory outside its allocated range, but they do not understand the layout of variables inside that range. A buffer overflow can corrupt neighboring structures while staying within the allowed address space, so the protection fails. Options B, C, and D are incorrect: user programs cannot modify the registers, limits are not autoโ€‘expanded, and encryption is unrelated to overflow detection.

Q11. Given base = 2000, limit = 500, a program issues a logical address 2300. Determine whether the access is allowed and, if so, compute the physical address.

A.Allowed, physical address = 4300
B.Allowed, physical address = 2300 โœ…
C.Not allowed, trap occurs
D.Allowed, physical address = 2000 + 2300 = 4300 (same as A)
๐Ÿ’ก Difficulty: hard | โœ… Correct: B

๐Ÿ“– Explanation: The logical address 2300 exceeds the limit of 500, meaning it lies outside the process's permitted range. The hardware therefore generates a protection fault, and the access is denied. Because the address is invalid, no physical address is calculated. Options A and D incorrectly assume the address is valid and perform the addition, while option B mistakenly treats the logical address as the physical address without applying the base.

Q12. During swapping, which register must be saved to ensure the process can resume execution at the correct point after being swapped back in?

A.Base Register
B.Stack Pointer
C.Program Counter โœ…
D.Limit Register
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– Explanation: The program counter holds the address of the next instruction to execute. When a process is swapped out, its current execution point must be preserved so that, after being swapped back in, it can continue exactly where it left off. Saving the base, limit, or stack pointer alone would not guarantee correct continuation; only the program counter provides that precise location.

Q13. How does enforcing privileged instruction execution only in kernel mode enhance the security of a swapping system?

A.It prevents user programs from directly modifying hardware registers that control memory protection โœ…
B.It allows user programs to bypass OS checks
C.It encrypts swapped pages
D.It speeds up context switches
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– Explanation: Privileged instructions, such as those that load base and limit registers, are only allowed in kernel mode. This restriction stops user programs from altering the memory protection mechanism, ensuring that only the operating system can change address limits or base addresses. Consequently, malicious or buggy user code cannot compromise isolation. Options B, C, and D describe effects that are either opposite of the security goal or unrelated to privilege enforcement.

Q14. The system is low on free memory and decides to swap out Process X. Which ordered steps does the OS typically perform?

A.Save registers, write process memory to disk, update page table, release frames โœ…
B.Release frames, write registers to disk, update page table, write memory to disk
C.Write process memory to disk, save registers, update page table, free frames
D.Save registers, update page table, write memory to disk, free frames
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– Explanation: The usual sequence begins by saving the process's registers so its execution state is preserved. Next, the OS writes the process's memory contents to secondary storage, updates the page table to mark those pages as swapped out, and finally releases the physical frames for other uses. Options B, C, and D reorder these steps in ways that could lose state or waste resources.

Q15. What is the relationship between a limit register's value and the maximum size of a process's address space?

A.Limit register equals the number of processes
B.Limit register defines the highest permissible logical address plus one โœ…
C.Limit register stores the physical address of the last byte
D.Limit register is unrelated to process size
๐Ÿ’ก Difficulty: medium | โœ… Correct: B

๐Ÿ“– Explanation: The limit register holds the size of the addressable range for a process; it specifies the largest legal logical offset (often expressed as the highest address plus one). This value, together with the base register, determines the total size of the process's virtual address space. The other options misinterpret the purpose of the limit register or claim no relationship, which is inaccurate.

๐Ÿ”— Related Topics (MCQs)