Quiz 5 Flashcards
One way to allow multiple processes to share memory is to simply save /restore the entire content of the memory with each context switch. However, this approach is not used as it is too inefficient.
True False
True
The following code is correct from a memory allocation standpoint:
int* b = (int*)malloc(sizeof(int));
if (argc < 3) free(b);
else printf(“%d\n”, argc);
free(b); return 0;
True False
False
The code has a logical issue regarding memory deallocation. Here’s why:
The pointer b is allocated memory using malloc(). If the condition argc < 3 is true, the memory is freed inside the if statement.
After the if-else block, the code frees b again (whether the condition was true or false). This results in double freeing if argc < 3, which is undefined behavior.
What happens when a process attempts to access a memory location?
No translation occurs as it is necessary
The program crashes as access to memory is never allowed
The physical address provided by the process is translated to a virtual address
The virtual address provided by the process is translated to a physical address
The virtual address provided by the process is translated to a physical address
What are the goals of a well-implemented virtual memory system? Select all that applies.
Protection: processes should not be able to affect each other’s address space
Transparency: memory virtualization should be invisible to running processes
Efficiency: the use of virtual memory should not slow down processes
Persistency: the content of memory should be backed up to disk whenever there is a crash
Protection: processes should not be able to affect each other’s address space
Transparency: memory virtualization should be invisible to running processes
Efficiency: the use of virtual memory should not slow down processes
Consider the virtual address space of a process. What is the text segment used for?
Dynamically allocated data structures
Local variables and arguments to functions
Program instructions
Strings used in/referenced by the program
Program Instructions
Suppose I write a small C program that prints the address of the main function. What does the output of the program represent?
A virtual memory address
A physical memory address
An offset in the hard drive where the executable is stored
An address which is both virtual and physical
A virtual memory address
Suppose I want to get the physical address of a C pointer from my program. Which system call should I use?
malloc()
getptr()
No system call can do this
getphysical()
No system call can do this
Consider the following code: int* b = malloc(sizeof(int));
After malloc returns, to which memory region does b point?
Heap
malloc never returns
Stack
Text
Heap
In explicit segmentation, the bits in a memory addresses are broken up into two parts. What are their names?
Segment and bounds
Segment and program counter
Segment and offset
Base and bounds
Segment and offset
In a segmentation-based virtual memory system, protection bit could be used to prevent execution of code in a segment
True False
True
In the context of virtual memory, what does the term relocation refer to?
Allowing the executable file (program) to be moved to different directories on disk
Ensuring that multiple processes can share the same address space
Ensuring that a process can execute on different computers on a network
Ensuring that a process works regardless of where it is placed in memory
Ensuring that a process works regardless of where it is placed in memory
In a system using virtual memory, what happens when a program attempts to access an invalid memory address? Order the steps in the correct sequence.
____ The program is terminated
____ The hardware detects the address is out of bounds
____ A trap into the OS is executed
__3__ The program is terminated
__1__ The hardware detects the address is out of bounds
__2__ A trap into the OS is executed
In some cases, the same memory segment can be shared between different process address spaces
True False
True
What are some characteristics of dynamic relocation? Select all that applies.
Physical addresses are generated as bounds register - virtual address
It uses one register, the program counter
It uses two registers, the base registers and the bounds register
Physical addresses are generated as virtual address + base register
It uses two registers, the base registers and the bounds register
Physical addresses are generated as virtual address + base register
Match the concept to its description
____
The address space is segmented in large chunks (e.g. stack/heap)
____
The address space is segmented in an arbitrary number of segments
- Coarse-grained segmentation
- Fine-grained segmentation
__1__
The address space is segmented in large chunks (e.g. stack/heap)
__2__
The address space is segmented in an arbitrary number of segments