Practice Questions (Part 2) Flashcards

(6 cards)

1
Q

How is a new process created? Select all that apply.

A. Via fork
B. Via exec
C. Via fork followed by exec
D. Via exec followed by fork
E. Via exec or fork followed by exec
F. Via fork or fork followed by exec
G. None of the above
H. All of the above
A

A, C, F

-Via fork
If we want to create a process that is an exact replica of the calling process

-Via fork followed by exec
If we want to create a process that is not an exact replica of the calling process

-Via fork or fork followed by exec
Either of the above two options

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

In the (pseudo) code segments for the producer code and consumer code, mark and explain all the lines where there are errors.

Global Section
int in, out, buffer[BUFFERSIZE];
mutex_t m;
cond_var_t not_empty, not_full;

Producer Code

  1. while (more_to_produce) {
  2. mutex_lock(&m);
  3. if (out == (in + 1) % BUFFERSIZE)) // buffer full
  4. condition_wait(&not_full);
  5. add_item(buffer[in]); // add item
  6. in = (in + 1) % BUFFERSIZE
  7. cond_broadcast(&not_empty);
  8. } // end producer code

Consumer Code

  1. while (more_to_consume) {
  2. mutex_lock(&m);
  3. if (out == in) // buffer empty
  4. condition_wait(&not_empty);
  5. remove_item(out);
  6. out = (out + 1) % BUFFERSIZE;
  7. condition_signal(&not_empty);
  8. } // end consumer code
A

Producer code
Line 3: uses “if” instead of “while”
Line 4: condition_wait doesn’t specify a mutex
Line 7: since only 1 item is added, no need to broadcast, should signal instead
Line 8: missing the mutex_unlock

Consumer code
Line 3: uses “if” instead of “while”
Line 4: condition_wait doesn’t specify a mutex
Line 7: condition_signal signals the wrong variable, should be signaling not_full
Line 8: missing the mutex_unlock operation

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

If the kernel cannot see user-level signal masks, then how is a signal delivered to a user-level thread (where the signal can be handled)?

A

Recall that all signals are intercepted by a user-level threading library handler, and the user-level threading library installs a handler. This handler determines which user-level thread, if any, the signal will be delivered to, and then it takes the appropriate steps to deliver the signal.

Note: If all user-level threads have the signal mask disabled and the kernel-level signal mask is updated, then and the signal remains pending to the process.

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

The implementation of Solaris threads described in the paper “Beyond Multiprocessing: Multithreading the Sun OS Kernel”, describes 4 key data structures used by the OS to support threads.

For each of these data structures, list at least two element they must contain:

  1. Process
  2. LWP
  3. Kernel-threads
  4. CPU
A

1) Process
- List of kernel level threads
- Virtual address space
- user credentials
- signal handlers

2) LWP
- User level registers
- System call arguments
- Resource usage info
- Signal mask

3) KLT
- Kernel-level registers
- stack pointer
- scheduling info
- pointer to LWP, Process & CPU structures

4) CPU
- Current thread scheduled on CPU
- List of kernel level threads
- Dispatching & interrupt handling info

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

An image web server has three stages with average execution times as follows:

  • Stage 1: read and parse request (10ms)
  • Stage 2: read and process image (30ms)
  • Stage 3: send image (20ms)

You have been asked to build a multi-threaded implementation of this server using the pipeline model. Using a pipeline model, answer the following questions:

  1. How many threads will you allocate to each pipeline stage?
  2. What is the expected execution time for 100 requests (in sec)?
  3. What is the average throughput of the system in Question 2 (in req/sec)? Assume there are infinite processing resources (CPU’s, memory, etc.)
A

1) Threads should be allocated as follows:
- Stage 1 should have 1 thread: This 1 thread will parse a new request every 10ms
- Stage 2 should have 3 threads: The requests parsed by Stage 1 get passed to the threads in Stage 2. Each thread picks up a request and needs 30ms to process the image. Hence, we need 3 threads in order to pick up a new request as soon as Stage 1 passes it.
- Stage 3 should have 2 threads: This is because Stage 2 will process an image and pass a request every 10ms (once the pipeline is filled). In this way, each Stage 3 thread will pick up a request and send an image in 20ms. Once the pipeline is filled, Stage 3 will be able to pick up a request and send the image every 10ms.

2) First request = 60 ms. The last stage will continue delivering the remaining 99 requests at 10ms intervals. So, the total is 60 + (99 * 10ms) = 1050ms = 1.05s
3) 100 req / 1.05s = 95.2 req/s

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

For data sets where the data set size is less than 100 MB why does…

  1. Flash perform worse than SPED?
  2. Flash perform better than MP?
A

1) In both cases the dataset will likely fit in cache, but Flash incurs an overhead on each request because Flash must first check for cache residency. In the SPED model, this check is not performed.
2) When data is present in the cache, there is no need for slow disk I/O operations. Adding threads or processes just adds context switching overheads, but there is no benefit of “hiding I/O latency”.

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