ICT1007-Part1-Tutorial2(Answer)
ICT1007-Part1-Tutorial2(Answer)
Answer:
In general, the operating system must save the state of the currently running process and
restore the state of the process scheduled to be run next. Saving the state of a process
typically includes the values of all the CPU registers in addition to memory allocation.
Context switches must also perform many architecture-specific operations, including
flushing data and instruction caches.
2. Using the program shown below, explain what the output will be at LINE A. What will the
value be if this is using pthread? Justify the answer with an explanation. You are encouraged
to code the following to verify your answer.
Answer:
5, Reason: After the fork, OS will create a different child process which is completely
different from the parent process with their own copy of code and addresses. Thus, the
addition of 15 to the value will only affect the child process and not the parent. The parent
value will remain as
20, pthread is using the same memory as the calling process (parent).
3. Including the initial parent process, how many processes are created by the program shown
in the following figure? Illustrate the process with a tree structure.
Answer:
8, ICT1007-Part1-04
Main
4. Why is it important for the scheduler to distinguish between I/O bound programs and CPU-
bound programs?
Answer:
• I/O bound programs: short CPU burst before I/O, typically do not use up time
slice/quantum
• CPU bound programs: a few long CPU burst, use up entire time slice/quantum without
performing any I/O
• Good to have priority for I/O bound programs ahead of CPU bound programs.
• Lecture slides: ICT1007-part1-05
•
5. Consider a system running ten I/O-bound tasks and one CPU-bound task. Assume that the
I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that
each I/O operation takes 10 milliseconds to complete. Also assume that the context-
switching overhead is 0.1 millisecond and that all processes are long-running tasks. Describe
the CPU utilization for a round-robin scheduler when:
Answer:
• Time quantum is 1ms with 0.1ms context-switching cost per context-switch. The I/O-
bound or CPU-bound tasks will each run for 1ms before being switched out. CPU
utilisation = 11x1 / 11x(1.1) = 1/1.1 = 91%.
• Time quantum is 10ms with 0.1ms context-switching cost per context-switch. The I/O-
bound tasks will each run for 1ms and the CPU-bound tasks will run for 10ms before
being switched out. CPU utilisation = (10+10) / (10x(1+0.1) + 1x(10+0.1)) = 20/21.1 =
94%.
Answer:
If a user-level program is given the ability to disable interrupts, then it can disable the timer
interrupt and prevent context switching from taking place, thereby allowing it to use the
processor without letting other processes execute.
7. Consider the exponential average formula used to predict the length of the next CPU burst.
What are the implications of assigning the following values to the parameters used by the
algorithm?
• α = 0 and τ0 = 100 milliseconds
• α = 0.99 and τ 0 = 10 milliseconds
Answer:
When α = 0 and τ0 = 100 milliseconds, the formula always makes a prediction of 100
milliseconds for the next CPU burst. When α = 0.99 and τ0 = 10 milliseconds, the most recent
behavior of the process is given much higher weight than the past history associated with
the process. Consequently, the scheduling algorithm is almost memoryless, and simply
predicts the length of the previous burst for the next quantum of CPU execution.
Answer:
Process Thread
1. Generally, more than one process cannot Threads of the same process can share
share the same memory. Sharing memory the same memory unless they are
among processes requires additional specially allotted separate memory
memory- locations.
management schemes.
2 Process creation, process execution, and Thread creation, thread execution, and
process switch are time consuming. thread switch are much faster in
comparison.
ICT1007-Part1-Tutorial 2
3. Processes are generally loosely coupled As the threads of a process are tightly
and so a lesser amount of resource sharing coupled; a greater amount of resource
is possible. sharing is
Answer:
10. Race conditions are possible in many computer systems. Consider a banking system with
two methods: deposit(amount) and withdraw(amount). These two methods are passed the
amount that is to be deposited or withdrawn from a bank account. Assume that a husband
and wife share a bank account and that concurrently the husband calls the withdraw()
method and the wife calls deposit(). Describe how a race condition is possible and what
might be done to prevent the race condition from occurring.
ICT1007-Part1-Tutorial 2
Answer:
Assume the balance in the account is 250.00 and the husband calls withdraw(50) and the
wife calls deposit(100). Obviously the correct value should be 300.00. Since these two
transactions will be serialized.
the local value of balance for the husband becomes 200.00, but before he can commit the
transaction, the deposit(100) operation takes place and updates the shared value of balance
to 350.00.
We then switch back to the husband and the value of the shared balance is set to 200.00.
Obviously an incorrect value.