Sie sind auf Seite 1von 4

Chapter 3 Processes

PARENT: value = 5
3.8 Describe the differences among short-term, medium-term, and longterm
Short Term Scheduler:
In the case of short term scheduler, the processes in the memory that are ready to
execute are selected and CPU will be allocated to these processess. It is also called
as CPU Scheduler.
Medium term scheduler:
Processes from the ready or blocked queue will be selected and removes them from
memory. These processes will be re instantiated later for running.
Long term Scheduler :
It is also called as job Scheduler. It chooses the processes that are to be placed into
the ready queue.
3.9 Describe the actions taken by a kernel to context-switch between
1. In response to a clock interrupt, the OS saves the PC and user stack pointer
of the currently executing process, and transfers control to the kernel clock
interrupt handler,
2. The clock interrupt handler saves the rest of the registers, as well as other
machine state, such as the state of the floating point registers, in the process
3. The OS invokes the scheduler to determine the next process to execute,
4. The OS then retrieves the state of the next process from its PCB, and restores
the registers. This restore operation takes the processor back to the state in

which this process was previously interrupted, executing in user code withuser
mode privileges.
3.12 Including the initial parent process, how many processes are created by
the program shown in Figure 3.32?
child pid =0
child pid1 =2603
parent pid =2600
parent pid1=2602
Chapter 4 Threads

4.4 What resources are used when a thread is created? How do they differ
from those used when a process is created?
Because a thread is smaller than a process, thread creation typically
uses fewer resources than process creation.Creating either a user or kernel thread
involves allocating a small data structure to hold a register set, stack,
and priority.
4.12 Using Amdahls Law, calculate the speedup gain of an application that
has a 60 percent parallel component for (a) two processing cores and (b)
four processing cores.
(a) two processing cores
speed up is 1.43
(b) four processing cores
speed up is: 1.82

CHILD: value = 5
PARENT: value =0
chapter 5

Process Synchronization

5.3. What is the meaning of the term busy waiting? What other kinds of waiting are
there in an operating system? Can busy waiting be avoided altogether? Explain your
Answer: Busy waiting means that a process iswaiting for a condition to be satisfied
in a tight loop without relinquishing the processor. Alternatively, a process could
wait by relinquishing the processor, and block on a condition and wait to be
awakened at some appropriate time in the future. Busy waiting can be avoided but
incurs the overhead associated with putting a process to sleep and having to wake
it up when the appropriate program state is reached.
5.4 Explain why spinlocks are not appropriate for single-processor systems yet are
often used in multiprocessor systems.
Answer: Spinlocks are not appropriate for single-processor systems because the
condition that would break a process out of the spinlock can be obtained only by
executing a different process. If the process is not relinquishing the processor, other
processes do not get the opportunity to set the program condition required for the
first process to make progress. In a multiprocessor system, other processes execute
on other processors and thereby modify the program state in order to release the
first process from the spinlock.
5.7 Race conditions are possible in many computer systems. Consider a banking
system that maintains an account balance with two functions: deposit(amount) and
withdraw(amount). These two functions are passed the amount that is to be
deposited or withdrawn from the bank account balance. Assume that a husband and
wife share a bank account. Concurrently, the husband calls the withdraw() function
and the wife calls deposit(). Describe how a race condition is possible and what
might be done to prevent the race condition from occurring
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
300.00. We then switch back to the husband and the value of the shared balance is
set to 200.00 obviously an incorrect value.

5.17 Assume that a system has multiple processing cores. For each of the following
scenarios, describe which is a better locking mechanisma spinlock or a mutex lock
where waiting processes sleep while waiting for the lock to become available:
The lock is to be held for a short duration.
The lock is to be held for a long duration.
A thread may be put to sleep while holding the lock
Answer : If the lock is to be held for a short duration, it makes more sense to use a
spinlock as it may in fact be faster than using a mutex lock which requires
suspending and awakening - the waiting process. If it is to be held for a long
duration, a mutex lock is preferable as this allows the other processing core to
schedule another process while the locked process waits. If the thread may be put
to sleep while holding the lock, a mutex lock is definitely preferable as you wouldn't
want the waiting process to be spinning while waiting for the other process to wake