Uploaded by Leela Krishna

OS question paper Part 1- answered some

advertisement
Part 1: Short answer questions: (10*4=40 Marks)
1) What happens in a Context switch?
Context switching is an operating system technique or approach for transitioning a process
from one state to another in order to execute its purpose using the system's CPUs. When the
system switches, the former running process's state is stored in registers, and the CPU is
assigned to a new process to execute its tasks. The preceding process must wait in a ready
queue while a new process is operating in the system.
During a context switch, the kernel will save the context of the old process in its PCB
and then load the saved context of the new process scheduled to run.
2) What are system calls?
3) Give the memory layout of a C program
4) Difference between Threads and Process
Process
Thread
Process means any program is in
1.
execution.
Thread means segment of a process.
Process takes more time to
2.
terminate.
Thread takes less time to terminate.
3.
It takes more time for creation. It takes less time for creation.
It also takes more time for
4.
context switching.
It takes less time for context switching.
Process is less efficient in term of
5.
communication.
Thread is more efficient in term of communication.
Process consume more
6.
resources.
Thread consume less resources.
7.
Process is isolated.
Threads share memory.
Process is called heavy weight
A Thread is lightweight as each thread in a process
8.
process.
shares code, data and resources.
5) What are the criteria for comparing CPU Scheduling algorithms
Many criteria have been suggested for comparing CPU scheduling algorithms.
1.CPU utilisation –
The main objective of any CPU scheduling algorithm is to keep the CPU as busy as
possible.
2.Throughput –
A measure of the work done by CPU is the number of processes being executed and
completed per unit time. This is called throughput.
3.Turnaround time –
The time elapsed from the time of submission of a process to the time of completion is
known as the turnaround time.
4.Waiting time –
A scheduling algorithm does not affect the time required to complete the process once
it starts execution. It only affects the waiting time of a process.
5.Response time –
In an interactive system, turn-around time is not the best criteria. A process may
produce some output fairly early and continue computing new results while previous
results are being output to the user.
6) Explain Race condition with an example.
a race condition is a condition of a program where its behavior depends on relative timing
or interleaving of multiple threads or processes.
Example: a simple example is a bank funds transfer or Logic gates handling Boolean
values.
7) Draw a diagram showing the parent/child relationships among the processescreated
by the following code fragment. Also show which call to fork created each process.
pid = fork() /* call #1 */
if (pid != 0)
fork() /* call #2 */
fork()
/* call #3 */
ans:
P
#1
#3
#2
#3
#3
8) Most hardware provides user mode and kernel mode; user processes are run in user
mode, while the OS runs in kernel mode. The tricky part is transitioning from user
mode to the kernel mode, which is caused by an event.Please give two examples of
events, and pick one example to further explain what takes place during that event.
The transition from user mode to kernel mode occurs when the application requests the help
of operating system or an interrupt or a system call occurs. The mode bit is set to 1 in the
user mode. It is changed from 1 to 0 when switching from user mode to kernel mode.
9) A spin lock acquire() can be implemented with a test-and-set instruction as
follows:
while (test-and-set(&lock->held) == 1)
; // spin
Recall that test-and-set() returns the old value at the address while atomically
setting it to 1.
Now a new lock acquire() is implemented as follows:
1: while (1) {
2:
while (lock->held > 0)3:
; // spin
4:
if (test-and-set(&lock->held) == 0)
5:
6: }
return;
Does it work? How does it change the behavior of the lock compared to thefirst
implementation?
10) What are the characteristics which any solution to Critical section problem must
have? Give an example where the solution must satisfy 2 characteristicsand not
satisfy the third characterist
Download