>Computer Science homework help

Prof. Pitts CS554AH1: Operating Systems Spring 2021
Homework Assignment 1
Answer each of the questions below. Do not copy the questions to your document, but label each answer in your
submission with the number of the homework question it belongs to. If you use a source other than your textbook in
your answer, cite the references that you used for that question. Do not copy and paste your answers as you will lose
marks; use your own words to rephrase the information you use from other sources. Do not submit scanned
handwritten assignments. Submit your answers as a PDF file through Canvas.
1. Review the discussion in Chapter 2 on policy and mechanism. Categorize each of the operating systems functions
below as a policy or a mechanism and explain your choice.
a. deciding which chunk of heap memory to give to a requesting process
b. setting the permissions on a file
c. creating a new operating system process
d. picking which process to schedule to the CPU next
2. For each of the instructions listed below, state whether that instruction should be allowed in user mode or only in
kernel mode, and explain your answer.
a. Change a process’s scheduling priority.
b. Set the access time of file.
c. Read the access time of a file.
d. Enable all interrupts.
3. What is an interrupt? What special instruction can trigger a software interrupt? How does the operating system
handle interrupts?
4. Consider the following partial timeline of process events:
Time Event
3 Process P3 executes the command: Read from disk unit 1
10 P1 executes the command: Write to disk unit 1
15 P4 executes the command: Read from disk unit 3
21 Disk unit 3 generates an interrupt: Read is complete for P4
23 Disk unit 1 generates an interrupt: Read is complete for P3
30 P4 executes the command: Write to disk unit 3
33 P2 terminates
35 Disk unit 1 generates an interrupt: Write is complete for P1
41 Disk unit 1 generates an interrupt: Write is complete for P4
Assuming that before time 3, no I/O requests were made, and that no I/O requests were made between time 41 and
50, complete the following state table by identifying each process as either ready/running, blocked for I/O, or
terminated. (Note: Time 19 has been completed for you in order to provide an example of how to fill out the table
entries.)
Time P1 P2 P3 P4
19 Blocked for I/O Ready/running Blocked for I/O Blocked for I/O
28
34
50
1/2
Prof. Pitts CS554AH1: Operating Systems Spring 2021
5. Consider the many-to-one model for mapping user-level threads to kernel-level threads. Suppose that a program
creates nine user-level threads (T0, T1, T2, T3, and T4). These threads have dependencies shown by the graph below: T1, T2,
and T3 depend on T0 and T4 depends on T1, T2, and T3. If a thread A is dependent on thread B, thread A must run after thread
B and A and B cannot run concurrently. This is a transitive property: because T4 is dependent on T3 which is dependent on
T0 , then T4, T3, and T0 are all dependent and none can run in parallel. Only if there is no dependency between two threads,
can they run concurrently on different cores of a multicore processor. For example, T1 and T3 have no dependency
relationship defined in the graph and so can run concurrently, but T0 and T4 cannot run concurrently because T4 depends on
T2 which depends on T0. That is, T0 must run before T2 which must run before T5. Answer the questions below. Be sure to
cite the references you use for this question.
T0
T1
T2
T3
T4
a. Identify the sets of threads which can run in parallel and can take advantage of a multicore processor.
b. What is the smallest number of kernel-level threads to maximize parallelism and how do the user-level threads
map to the kernel threads.
6. Assume process P1 has threads T1 and T2 and P2 has threads T3 and T4. How do threads T1 and T2
communicate? How do threads T3 and T4 communicate? How could threads T1 and T3 communicate? Explain
your answer.
7. Consider the code below that uses the fork system call:
8. #include <stdio.h>
int main()
{
printf(“%d\n”,getpid());
fork(); // fork A
printf(“%d\n”,getpid());
fork(); // fork B
printf(“%d\n”,getpid());
fork(); // fork C
printf(“%d\n”,getpid());
return 0;
}
Answer the questions below.
a. How many processes are created in total by this program (not including the original process).
b. Identify the parent/child relationships between the processes.
9. Suppose that an application can take advantage of the parallelism provide by a dual core processor 35% of
execution time. Use Amdahl’s Law to determine the overall speedup of the application on a dual core processor
versus a single core processor.
10. What are the three common ways of mapping user threads to kernel threads?
2/2