Operating Systems-EGC301, 2 Semester, 2024-25
Mid semester Exam; Maximum marks 60, Time Limit 150 minutes
March 6, 2025
1. [2+2+3+3=10]
(a) In a modern computer, when we turn on the laptop (say) which instructions does the CPU
first execute (before anything on any disk is read)? Where are those instructions?
(b) Further to the above, how does the OS (like Linux or Windows) begin to execute (assume
MBR based booting)?
(c) (i) How is the kernel/user mode bit used when a system call enters or returns (ii) What does
it prevent/ allow in which mode? (iii) Why is this useful?
(d) Say we compile a C program using gcc, once with the ”-static” flag and once without. Now
we are interested in looking for syscalls in the two processes/executables. (i) What would
be the difference in the output of strace for each executable (for the same input) in terms
of the syscalls made? (ii) What would be the difference in the output of objdump for each
executable, again in terms of looking for the syscalls in the executable. Explain both answers.
2. Read the code snippet below and the input information that follows: [3+5+2=10]
void duplicate(){ (a) How many read() system calls is the parent
char s[100]; likely to make? What caused those system
while (scanf("%s",s)> 0 ) calls, though the code above has no read()
printf("%s\n",s); calls in it? Why that number of system
} calls?
int main(){
(b) In the output while the two words “first”
int d;
and “thing” are printed twice each, the
scanf("%d",&d);
three words in the second line are printed
fork();
only once each. How do you explain this?
duplicate();
} // end of code snippet (c) The C library function fopen() returns a
Input lines (followed by EOF, i.e., ^D): FILE *, we also learnt that the Kernel
1 first thing maintains an open files table. Is the pointer
Second line here returned by fopen() likely pointing to the
open files table? Justify your answer.
3. [2+2+2+2+2=10]
(a) In a time shared operating system like Linux, explain the two normal situations under which
context switch from one process to another is likely to happen. Answer with respect to the
different process states and the corresponding transitions.
(b) Assume that the OS context switch code takes 100 cycles of a certain CPU. If the CPU runs
at 2 MHz, with a large set of CPU bound processes, what is the efficiency (% time spent in
user code, outside context switch) if the context switch is initiated exactly once every ms.
Everything else being the same, would the efficiency increase or decrease if we increased the
clock frequency to 4 MHz, compute and justify.
(c) A scheduler uses RR scheduling with fixed time slices and has a single run queue for all
processes, with processes always run from the beginning of the run queue and always added
to the end of the run queue. Assume further that the set of processes is fixed. However,
some processes are interactive while others are CPU bound. How does this negatively affect
interactive jobs - explain in terms of any metric.
1
(d) To alleviate the problem this queue was split into two RR queues - A high priority queue
for interactive processes and a low priority queue for CPU bound processes. How does this
two-queue scheduling negatively affect CPU bound tasks? - Explain in terms of any metric.
(e) In reality, we do not know that a process is interactive or CPU bound. Show how we can have
dynamic priority for processes to make the two queue solution work better (Take motivation
from Multilevel Feedback Queue).
4. [2 + 6 + 2 = 10]
(a) (i)Which data structure of a process points to entries in the open files table? (ii)The open
files table has a field that maintains the number of references to it. How do you think that is
used?
(b) In the C code snippet here, stir() and ap- int main(){
pend() are functions which read strings using q = fork();
scanf() do some transform and print strings if ( q==0 ) {
using printf(). stir() reads a random num- // process Q (child)
ber of strings, while append() reads until it stir();
reaches end of file. Augment the code so that }
Q reads from the terminal and its output goes
to P whose output appears on the terminal. else{
Use close() appropriately so that when the // process P (parent)
when Q exits, so does P. append();
}
}
(c) Relate the part of your code that is relevant to the question asked in part (a)(ii) above.
5. This is about a filesystem on the disk, in particular ext2, as discussed in class. [2+2+2+2+2=10]
(a) What is the link count field in an inode. How is it related to the “ln” command and to the
“rm” command.
(b) Let’s say an inode identifies a certain directory. What do the data block pointers in that inode
point to?
(c) What information does the blocks bitmap contain?
(d) What does a disk partitioning tool (like fdisk) do and what information does it produce?
(e) What does the make filesystem command (like mkfs) operate on and what does it do?
6. [3+4+3=10]
(a) A person has two equal sized hard disks with him. He has to choose between one of RAID-0
(pure striping) and RAID-1(pure replication).
i. Which one should he choose if his priority is to disk failure tolerance. Why?
ii. Which one is better if his priority is to improve disk-write performance. Why?
iii. Which one has more disk capacity. Why?
(b) Give two reasons why interrupt mechanism coupled with DMA for disk reads improves CPU
utilization over simple programmed IO ?
(c) For a normal file explain what I/O write buffering in the kernel is and explain why it improves
performance. Does it reduce the number of write() system calls – explain?