Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 3

Due in Section on Friday, September 21, 2018

The problem set must be completed before section and brought to section. To ensure that your problem set is turned in correctly and that you receive credit for discussion section, you must follow these guidelines exactly.
```Discussion Section Problem Set #:
Student Name:
EID:
Unique Number:
```
• You may either type your answers or write them by hand, but you must bring a hard copy to discussion section.
• In discussion section, your TA will check that you make a good effort on the problem set and that you are participating in the discussions in section and ready and able to answer when called upon. If all of those are true, you will receive credit for discussion section that day. Note that a "good effort" on the problem set includes that all answers are in your own words and not copied from anywhere else, including the slide deck.

1. Consider a system using a multilevel feedback queue scheduler. Its scheduler is configured to have four queues, which are, in order of highest priority to lowest priority: Q1, Q2, Q3, and Q4. The queues have quantums sized 5s, 10s, 20s, and 40s, respectively.

For each of the following three processes, determine which queue it is in when it begins its final quantum.

• Process A, runtime 40s, blocks every 2s.
• Process B, runtime 42s, never blocks.
• Process C, runtime 70s, blocks at 7s, 11s, 25s, 42s, 48s, where those times are points in its execution.

2. Given the following segment of code:
```char a[100];

{
int d;
static double b;
char * s = "boo";
char * p;

p = malloc(300);
return 0;
}
```
Identify the memory space in which each variable resides and indicate if the variable is private to a thread or shared amongst threads.

3. Given the following pseudocode:
```int i = 0;

int main(void)
{
fork();

if(/*CHILD*/)
{
i = i - 1;
return SUCCESS;
}
if(/*PARENT*/)
{
i = i + 1;
wait for child to terminate;

printf("i = %d\n", i);
}
}
```

• What is the output? Describe in detail why it is that way.
• Are there other possible outputs? Why or why not? If so, give another example of what the printed values of ``i'' might be and explain how to force the program to execute the same way each time.

4. Now consider this pseudocode involving kernel threads:
```int i = 0;

{
i = i - 1;
}

{
i = i + 1;
}

int main(void)
{