CMU Final 2012 Flashcards

1
Q

Each thread has its own:
(a)Heap
(b) Stack
(c)Global values
(d) Textdata

A

b. Stack

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

Simply decreasing the size of block headers used internally by malloc:
(a)Decreases internal fragmentation
(b) Increases internal fragmentation
(c)Decreases external fragmentation
(d) Increases external fragmentation

A

(a) Decreases internal fragmentation

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

Which of the following sentences about reader-writer locks is not true?
(a)Many readers can hold the same rwlock at the same time
(b)Two writers cannot hold the same rwlock at the same time
(c)Many readers and exactly one writer can hold the same rwlock at the same time
(d)An rwlock can be used as a mutex

A

(c) Many readers and exactly one writer can hold the same rwlock at the same time

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

Which of the following is the correct ordering (left-to-right) of a file’s compilation cycle (a file name
with no extension is an executable):
(a) foo.c→foo.o→foo.s→foo
(b) foo→foo.s→foo.o→foo.c
(c) foo.c→foo.s→foo→foo.o
(d) foo.c→foo.s→foo.o→foo

A

d) foo.c→foo.s→foo.o→foo

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

Suppose an int A is stored at virtual address 0xff987cf0, while another int B is stored at virtual address 0xff987d98. If the size of a page is 0x1000 bytes,
then A’s physical address is
numerically less than B’s physical address.
(a)Always true
(b)Always false
(c) Sometimes true, sometimes false (d)Not enough information

A

(a)Always true

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

Assuming no errors, which one of the following functions returns exactly once?
(a) fork()
(b) execve()
(c) exit()
(d) longjmp()
(e) waitpid()

A

(e) waitpid()

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

On a 64-bit system, which of the following C expressions is equivalent to the C expression (x[2]+4)[3]? Assume x is declared as int **x.
(a) (((x+16))+28)
(b) (((x+2))+7)
(c) (x+28)
(d) (((x)+2)+7)
(e) (
(x+2)+7)

A

(b) (((x+2))+7)

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

When can short counts occur?
(a)When an EOF is encountered during a read
(b)When a short int is used as a counter (c)When reading or writing to disk files (d)When the kernel runs out of kernel memory

A

(a) When an EOF is encountered during a read

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

A program blocks SIGCHLD and SIGUSR1. It is then sent a SIGCHLD, a SIGUSR1, and another SIGCHLD, in that order. What signals does the program receive after it unblocks both of those signals (you may assume the program does not receive any more signals after)?

(a) None, since the signals were blocked they are all discarded.
(b) Just a single SIGCHLD, since all subsequent signals are discarded.
(c) Just a single SIGCHLD and a single SIGUSR1, since the extra SIGCHLD is discarded.
(d) All 3 signals, since no signals are discarded.

A

(c) Just a single SIGCHLD and a single SIGUSR1, since the extra SIGCHLD is discarded.

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

Which of the following events does not generate a signal?
(a)Division by zero
(b)A new connection arrives on a listening socket
(c) A write is attempted on a disconnected socket
(d)NULL is dereferenced
(e)A process whose parent has already terminated exits

A

(b)A new connection arrives on a listening socket

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

In an x86-64 system, how many integers can be stored in a cache line if your cache is 4KB, is 4-way set-associative and contains 4 sets?
(a) 8
(b) 16
(c) 32
(d) 64
(e) 128

A

(d) 64

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

Which types of locality are leveraged by virtual memory?
(a) Spatial locality
(b) Temporal locality
(c) Prime locality
(d)Both (a) and (b)
(e)Both (b) and (c)

A

(d)Both (a) and (b)

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

Which of the following is not a section of an ELF file?
(a) .text
(b) .static
(c) .rodata
(d) .data
(e) .bss

A

(b) .static

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

Choose the true statement.
(a)All thread-safe functions are reentrant.
(b) Some reentrant functions are not thread-safe.
(c) It is never a good idea to use a persistent state across multiple function calls.
(d) It is impossible to have a race condition between two threads as long as they have no shared state.
(e) All functions which call non-thread-safe functions are themselves not thread safe.

A

(d) It is impossible to have a race condition between two threads as long as they have no shared state.

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

We use dynamic memory because:
(a) The heap is significantly faster than the stack.
(b) The stack is prone to corruption from buffer overflows.
(c) Storing data on the stack requires knowing the size of that data at compile time.
(d)None of the above.

A

(c) Storing data on the stack requires knowing the size of that data at compile time.

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

In the following code, a parent opens a file twice, then the child reads a character: char c; int fd1=open(“foo.txt”,O_RDONLY);
int fd2=open(“foo.txt”,O_RDONLY); if(!fork()){ read(fd1,&c,1); }
Clearly, in the child, fd1 now points to these cond character of foo.txt. Which of the following is now true in the parent? (a) fd1 and fd2 both point to the first character.
(b) fd1 and fd2 both point to the second character.
(c) fd1 points to the first character while fd2 points to the second character.
(d) fd2 points to the first character while fd1 points to the second character.

A

(d) fd2 points to the first character while fd1 points to the second character.

17
Q

Which of the following is true about races?
(a) A race occurs when correctness of the program depends on one thread reaching point a before another thread reaches point b.
(b) Exclusive access to all shared resources eliminates race conditions. (c)Race conditions are the same as deadlocks.
(d) All race conditions occur inside loops, since that is the only way we can interleave processes.

A

(a) A race occurs when correctness of the program depends on one thread reaching point a before another thread reaches point b.

18
Q

Consider the following two blocks of code, which are contained in separate files: /* main.c / inti=0; intmain(){ foo(); return0; } / foo.c */ inti=1; voidfoo(){ printf(“%d”,i); } What will happen when you attempt to compile, link, and run this code?
(a) It will fail to compile.
(b) It will fail to link.
(c) It will raise a segmentation fault.
(d) It will print“0”.
(e) It will print“1”.
(f) It will sometimes print “0” and sometimes print “1”.

A

(b) It will fail to link.