You are on page 1of 5

COMP3230A/B Principles of Operating Systems

Problem Set #1
Due date: 23:59 pm, October 3rd, 2021
Total 8 points
(version: 1.0)
Note: This assignment weights a total of 8 points in the final marks of this course. However, just like each process
has its own private virtual address space, this assignment also has its own virtual score space of 100 points, which
is mapped to 8 points of physical marks. The below points for each question are given in the said virtual score
space.

Question 1 – Process (12 points)


Answers:
a. (Each for 1 point)
1) Blocked
2) Ready
3) Running
4) Blocked
5) Terminated
b. (Each gets 1 point, and the reasons for not possible cases get 1 point respectively.
1) Not Possible (1 point): A process must be Ready before it can run again. (1 point)
2) Possible
3) Possible
4) Possible
5) Not Possible (1 point): A Zombie process is dead and there is no state beyond Zombie.
(1 point)

Question 2 – Process Control (20 points)

Answer:

a. 16 processes are created (including the process running main()).


b. 16 SIGCHLD signals are generated as there are 16 processes; each generates one SIGCHLD
signal upon termination.
c. In the execution, this printf() statement is never executed. It is because only the child processes at
the 4th fork would continue to waitpid() after the “if_else” block. As they do not have any child
processes, waitpid() should return -1; thus, the printf() statement never runs.
d. It doesn’t work! The shell replaces the calling process with the new command called in exec(),
and so it never forks.
Question 3 – CPU Virtualization (8 points)

Answers:

1) The process’s PC, general purpose registers are saved in the kernel stack rather than the user
stack.
2) Returns from the kernel require a special instruction (return-from-trap instruction), which both
undoes what the trap did (restores saved state), and changes privileged mode back to user mode.
3) Retry only happens in some cases (e.g., TLB miss); in other cases (e.g., syscall trap), the return
must return to the instruction after the trapping instruction.

Question 4 – Interrupts (10 points)

Answers (each for 2 points):

1) I
2) E
3) E
4) I
5) N

Question 5 – CPU Virtualization (10 points)

Answer:

Yes, it is possible (1 point). If the HW does not support trap, an OS can use exceptions instead.

The trap instruction allows a controlled and protected transition from user mode to kernel mode.
Exceptions like divide by zero or invalid memory access can also cause switching from user mode to
kernel mode. The OS can implement an invalid instruction as a substitute for trap instruction because an
invalid instruction will cause an exception that immediately transfers control to the OS.

(Optional) How to implement system call and pass by arguments with this design: values like system call
number and arguments can be put on the process stack. The OS can verify and check the values to
distinguish whether it is an invalid operation for a system call or it is actually an invalid instruction
executed by the process.
Question 6 - Process Scheduling (40 points)

Answer:

a)
FIFO
1 1 1 2 2 3 3
0 1 3 5 7 8 0 3 5 0 5 0 5
P1
P2
P3
P4
P5
P6
P7
Average turnaround time = (10 + 15 + 16 + 20 + 20 + 23 + 22) / 7 = 18
Average waiting time = Average response time = (0 + 9 + 13 + 12 + 19 + 18 + 20) / 7 = 13

SJF
1 1 1 2 2 3 3
0 1 3 5 7 8 0 3 5 0 5 0 5
P1
P2
P3
P4
P5
P6
P7
Average turnaround time = (10 + 26 + 11 + 28 + 3 + 11 + 3) / 7 = 13.14
Average waiting time = Average response time = (0 + 20 + 8 + 20 + 2 + 6 + 1) / 7 = 8.14

STCF
1 1 1 2 2 3 3
0 1 3 5 7 8 0 3 5 0 5 0 5
P1
P2
P3
P4
P5
P6
P7
Average turnaround time = (35 + 10 + 3 + 19 + 1 + 8 + 2) / 7 = 11.14
Average waiting time = (25 + 4 + 0 + 11 + 0 + 3 + 0) / 7 = 6.14
Average response time = (0 + 0 + 0 + 11 + 0 + 1 + 0) / 7 = 1.71
Round robin
1 1 1 2 2 3 3
0 1 3 5 7 8 0 3 5 0 5 0 5
P1
P2
P3
P4
P5
P6
P7
Average turnaround time = (30 + 19 + 13 + 28 + 7 + 23 + 11) / 7 = 18.71
Average waiting time = (20 + 13 + 10 + 20 + 6 + 18 + 9) / 7 = 13.71
Average response time = (0 + 1 + 3 + 5 + 6 + 6 + 9) / 7 = 4.29

b)
MLFQ
1 1 1 2 2 3 3
0 1 3 5 7 8 0 3 5 0 5 0 5
P1
P2
P3
P4
P5
P6
P7
Average turnaround time = (33 + 23 + 8 + 28 + 1 + 19 + 5) / 7 = 16.71
Average waiting time = (23 + 17 + 5 + 20 + 0 + 14 + 3) / 7 = 11.71
Average response time = (0 + 0 + 1 + 0 + 0 + 1 + 1) / 7 = 0.43

You might also like