OS T1 Model Solution - June 1 2023
OS T1 Model Solution - June 1 2023
Interrupts:
Interrupts are signals sent to the processor by external devices or internal
mechanisms to request attention or notify the processor of an event that needs to
be handled. The purpose of interrupts is to interrupt the normal execution flow of a
program and transfer control to a specific interrupt handler or interrupt service
routine (ISR). Interrupts are typically used for time-critical events or to handle
asynchronous events such as hardware interrupts, I/O operations, timers, or other
external signals.
When an interrupt occurs, the processor saves its current state and transfers control
to the appropriate interrupt handler, which is a predefined routine responsible for
handling that specific interrupt. Once the interrupt handler completes its execution,
the processor resumes the interrupted program from where it left off.
Interrupts are classified into different types, such as hardware interrupts (e.g.,
keyboard input, mouse input, disk I/O), software interrupts (e.g., system calls), and
exceptions (e.g., divide-by-zero, page faults).
Traps:
Traps, also known as exceptions or software interrupts, are synchronous events that
occur during the execution of a program. Unlike interrupts, traps are intentionally
triggered by executing specific instructions or encountering certain conditions
within the program itself. Traps are typically used for error handling or for executing
privileged instructions that require a transition to a higher privilege level.
When a trap occurs, the processor saves its current state and transfers control to the
corresponding trap handler. The trap handler can perform tasks such as error
handling, exception processing, or executing a specific routine associated with the
trap. After the trap handler completes its execution, control is returned to the point
in the program where the trap was triggered.
Traps can be used for a variety of purposes, including division by zero errors,
memory protection violations, debugging, system calls, or software breakpoints.
Q 1B) Justify, “Frequent switching amongst CPU jobs is the principle theme of time-sharing
operating system”.
The statement can be justified based on the fundamental principles and objectives
of time-sharing systems as follows:
Time slicing: Time-sharing systems typically employ a technique called time slicing
or time quantum, where each process is allocated a small time slice to execute
before switching to another process. This time-slicing mechanism allows the
operating system to provide the illusion of concurrent execution and fairness
among processes, even though the CPU is executing them sequentially.
During a context switch, the operating system saves the current PCB of the running
process and loads the PCB of the next process to be executed. This switch involves
updating the necessary fields in the PCB, such as the program counter and CPU
registers, to ensure a seamless transition between processes. By utilizing the PCB,
the operating system can efficiently switch between processes, allowing for
multitasking and the illusion of concurrent execution.
Q 3 (b)
) Consider the following synchronization construct used by the processes:
Here, value1 and value2 are shared variables. Which of the following solutions to
critical section problem (mutual exclusion, progress and bounded wait) are satisfied
by the above construct? Explain.
(Mutual exclusion because no two processes can enter critical section at the same
time. If one process is in the critical section, then other has to wait. Assume P1 is in
critical section (it means value1=true, value2 can be anything, true or false). So this
ensures that p2 won’t enter in critical section and vice versa. This satisfies the
property of mutual exclusion. Here bounded waiting condition is also satisfied as
there is a bound on the number of process which gets access to critical section after
a process request access to it)
Two processes, P1 and P2, need to access a critical section of code. Here, value1and
value2 are shared variables, which are initialized to false.
Now, when both value1and value2 become true, both process p1 and p2 enter in
while loop and waiting for each other to finish. This while loop run indefinitely which
leads to deadlock.
Progress is not satisfied here because when both the process execute and get
preempted then both the processes waiting for each other to release the flag.
Which is not going to happen without entering the critical section. So they will wait
for indefinite time, No progress. This situation is called "Deadlock".