EEL 602 -
Operating Systems
Spring 2007
Indian Institute of
Technology Delhi, New Delhi
Solutions Minor # 2
1. Short Answers (Please be explicit in your answers) [2 × 3 = 6]
(a) What state does a thread share with other threads in a process and what state is private/specific to a thread?
Shared state
(1) Contents of memory (global variables, heap)
(2) I/O state (file system)
Having both answers is worth 1 mark. Having one answer is worth 0.5 mark.
Private state
(1) CPU registers (including, program counter and stack pointer)
(2) Execution stack
Having both answers is worth 1 mark. Having one answer is worth 0.5 points
(b) What is Jacketing?
--- ----- -------
(c) List two reasons why overuse of threads is bad (i.e., using too many threads for different tasks).
(1) Threads are cheap, but they’re not free - Too many threads will cause a system to spend lots of time context switching and not doing useful work. Each thread requires
memory for stack space and TCBs. Too many threads and these memory uses will dominate overall memory use.
(2) Having many threads makes synchronization more complicated as you have more and more simultaneous tasks. Also, debugging is more difficult due to non-deterministic and
non-reproducible execution. We did not give credit for answers that were scheduling issues (e.g., too many threads could cause starvation), since these issues also affect
processes.
2. Consider a system with a mixture of I/O bound processes and CPU bound processes
(a) Explain how this mixture of processes maximizes system utilization. [1]
We want to keep all parts of the system busy by overlapping I/O operations with CPU operations. Overall, if we have some processes using the CPU while others are waiting
on I/O, then the system will be more utilized.
(b) Explain why this combination is more important in batch systems than it is on most computers sitting around in our department. [1]
In general, our systems are underutilized (there are a lot of wasted cycles both on I/O devices as well as CPU), and user interaction is more important. Batch systems were
expensive systems that were busy all the time.
3. For each of the following thread state transitions, say whether the transition is legal and how the transition occurs or why it cannot. [1 × 3 = 3]
(a) Change from thread state BLOCKED to thread state RUNNING.
Illegal. Threads must first be inserted into the ready queue (i.e., moved to the RUNNABLE state) before they can be executed (moved to the RUNNING state).
(b) Change from thread state RUNNING to thread state BLOCKED.
Legal. A thread that sleeps, joins with another thread, or waits on I/O will transition from the RUNNING state to the BLOCKED state.
(c) Change from thread state READY to thread state BLOCKED.
Illegal. A thread can’t change from the READY state to the BLOCKED state without first being scheduled and taking an action that causes it to block (e.g., the actions
listed in b).
4. Give two reasons why the following block of code is logically and semantically wrong. [5]
if ( fork() == 0 )
{ printf("Please wait for me");
args = n;
exec("/ajaykr/eel602/exams/minor/2007/mypgm", "mypgm", "abc", "xyz", 0);
printf("Now I'm back");
}
.
.
......
(1) printf("Now I'am back") will be overlaid by the "exec" function call and will not get executed if "exec" is successful.
(2) _exit(1) should follow printf("Now I'am back"). Without it, child process will not terminate properly when exec() fails.
5. Consider a 32 bit microprocessor, with a 16-bit external data bus, driven by an 8-MHz input clock. Assume that this microprocessor has a bus cycle whose minimum duration equals four input clock cycles. What is the maximum data transfer rate across the bus that this microprocessor can sustain in bytes/s? [2]
Clock cycle =
Bus cycle = 4 ´ 125 ns = 500 ns
2 bytes transferred every 500 ns; thus transfer rate = 4 MBytes/sec