Midterm_solution
Midterm_solution
4) (20 points) Write a C program using fork(),wait(), etc. functions which outputs “Hello world”; where “Hello” is printed in the child
process and “ world” is printed in the parent process. Note that the output should not be “ worldHello”.
…
int main() {
pid_t pid = fork();
if (pid < 0) { // Fork error
perror("Fork failed");
return 1;
} else if (pid == 0) { // Child process
printf("Hello");
} else { // Parent process
wait(); // Waits for the child to terminate
printf(" world”);
}
return 0;
}
5) (20 points) Consider the following empty memory blocks: 250, 500, 350, 750, and 125. A series of processes request memory in the
following sizes: 115, 450, 350, and 200. Using the Best Fit strategy:
a) Show which block is allocated to each process.
125 allocated for 115 remaining 10 memory units: 250, 500, 350, 750, 10
500 allocated for 450 remaining 50 memory units: 250, 50, 350, 750, 10
350 allocated for 350 remaining no memory units: 250, 50, 750, 10
250 allocated for 200 remaining 10 memory units: 50, 50, 750, 10
b) Show the final state of memory after all allocations: 50, 50, 750, 10
6) (10 points) Consider a process with a logical address space of 8 pages, each page size being 512 bytes. If the system has 64 frames in
physical memory, each of the same size as a page, calculate the number of bits required to represent the page number and the offset.