Os Past Papers' Solutions 2017
Os Past Papers' Solutions 2017
Os Past Papers' Solutions 2017
YEAR 2017
Q # 3:
Schedule the following processes using RR. The processes P1, P2 and P3 have
arrived at time unit 0, 1 and 2 respectively. The number inside the parenthesis
indicates the time units for CPU and I/O bursts. Assume a time quantum of 4 time
units.
Process CPU Burst I/O Burst CPU Burst I/O Burst CPU Burst
P1x 3x 6x 2x 4x 5(1)x
P2x 5(1)x 4x 3x x x
P3 6(2)x 8x 5(1)x 7 2
a. Gantt Chart:
P1 P2 P3 P1 P2 P3 P1 P2 P1 P3
0 3 7 11 13 14 16 20 23 24
P3 No P P3
28 29 33 36 38
Here, Waiting time= Finish Time – CPU Burst Time – Arrival Time
Average waiting time= 14 + 14 + 24 / 3
=17.33
Zombie Process:
A process which has finished the execution but still has entry in the process
table to report to its parent process is known as a zombie process. A child
process always first becomes a zombie before being removed from the
process table. The parent process reads the exit status of the child process
which reaps off the child process entry from the process table.
Orphan Process:
System call fork() is used to create processes. It takes no arguments and returns a
process ID. The purpose of fork() is to create a new process, which becomes
the child process of the caller. After a new child process is created, both processes
will execute the next instruction following the fork() system call. Therefore, we have
to distinguish the parent from the child. This can be done by testing the returned
value of fork():
• If fork() returns a negative value to the parent process as the PID, the
creation of a child process was unsuccessful.
• fork() returns a zero as PID if the new child process was create, and returns a
positive value, the process ID of the child process, to the parent.
• The returned process ID is of type pid_t defined in sys/types.h. Normally, the
process ID is an integer. Moreover, a process can use function getpid() to
retrieve the process ID assigned to this process.
meaning wait for any child process whose process group ID is equal to the
< -1
absolute value of pid.
>0 meaning wait for the child whose process ID is equal to the value of pid.
Solution of part b:
Here after creating variables int cpid and status,a fork () is executed and cpid will be
assigned with the code returned by fork (). Cpid will have one of three values; a
number greater than 0, a 0 or a negative number.
First, the statement “start execution” will be printed on screen.
• If (cpid > 0) is true, that means we are inside the parent process right now. The
wait (&status) will get the status of the newly created child process by fork() and
will wait until it terminates.
On the next line, again a fork () is executed to create one more child process.
Statement “between creation” will be printed and one more child process will be
created with fork(). The statement “Inside Parent Process” will be printed on screen.
On the next line, “Bye” is printed.
If, on the other hand, cpid was equal to 0, the Statement “Inside Child Process” will
be printed. Fork() will create a new child process here. On next line “Good Bye” will
be printed and exit (0) will be executed, which means that the code was executed
successfully and process will end.
In case of negative value of cpid, the process would have ended by giving an error
message as –ve number means child process creation wasn’t successful.
Q # 5:
Number of instances: A (9), B (3), C (6)
So the total available recourses: (9, 3, 6)
For Safe Sequence, select a process such that Need of the process < Available
resources.
Current Available Resources= (0, 1, 1)
1st Iteration:
Need (Process P2) = (0,0,1) < (0,1,1) Available resources
Process P2 completes and returns allocated resources, so
Current Available Resources = (0, 1, 1)
+ Resources Allocated to P2 = (6, 1, 2)
=Current Available Resources= (6, 2, 3)
2nd Iteration:
Need (Process P1) = (2,2,2) < (6,2,3) Available resources
Process P1 completes and returns allocated resources, so
Current Available Resources = (6, 2, 3)
+ Resources Allocated to P1 = (1, 0, 0)
=Current Available Resources= (7, 2, 3)
3rd Iteration:
Need (Process P3) = (1,0,3) < (7,2,3) Available resources
Process P3 completes and returns allocated resources, so
Current Available Resources = (7, 2, 3)
+ Resources Allocated to P3 = (2,1, 1)
=Current Available Resources= (9, 3, 4)
so now
Current Available Resources (9, 3, 6) = Total available recourses: (9, 3, 6)