Quiz 5 Flashcards

1
Q

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
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

The virtual address provided by the process is translated to a physical address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

Program Instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A virtual memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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()

A

No system call can do this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

Segment and offset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In a segmentation-based virtual memory system, protection bit could be used to prevent execution of code in a segment

True
False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

Ensuring that a process works regardless of where it is placed in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

__3__ The program is terminated
__1__ The hardware detects the address is out of bounds
__2__ A trap into the OS is executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In some cases, the same memory segment can be shared between different process address spaces

True
False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

It uses two registers, the base registers and the bounds register

Physical addresses are generated as virtual address + base register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

  1. Coarse-grained segmentation
  2. Fine-grained segmentation
A

__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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly