OS-SESSIONAL 1 SOLUTION
OS-SESSIONAL 1 SOLUTION
Instructions:
1. Answer sheet has been provided on th very LAST PAGE. It is mandatory to fill answer sheet.
Otherwise,your exam won’t be evaluated and you will be received zero.
2. Please refrain from removing the answer sheet of MCQs from exam. If you detect answer
sheet from exam, your exam will be canceled.
3. Mark your roll number in the answer sheet. Use 6 digits of your registration number (ignoring
alphabet) to fill roll number.
4. No additional sheet will be provided for rough work. Use the back of the last page for rough
work.
5. If you need more space write on the back side of the paper and clearly mark question and
part number etc.
6. After asked to commence the exam, please verify that you have Ten (10) different printed
pages including this title page. There are a total of 4 questions.
7. Use permanent ink pens only. Any part done using soft pencil will not be marked and cannot
be claimed for rechecking.
Consider the following C Program named “fork-tree.c”. Assume there are no errors in the program and
everything works. Dry run in the rough space provided. Then answer the questions below.
//C program named as "fork-tree.c"
int main()
{
for (int i = 0; i < 3; i++)
{
if (fork() == 0) {
printf(" * ");
printf("My process ID is %d\n", getpid());
printf("My parent process ID is %d\n", getppid());
exit(0);
} //end if (fork() == 0)
else
{
for (int j = 0; j < 2; j++) {
if (!fork() != 0) {
printf(" + ");
printf("My process ID is %d\n", getpid());
printf("My parent process ID is %d\n", getppid());
exit(0);
} //end if (!fork() != 0)
} //end for j
for (int k = 0; k < 2; k++)
wait(NULL);
} //end else
} //end for i
printf(" # ");
printf("My process ID is %d\n", getpid());
printf("My parent process ID is %d\n", getppid());
}//end main()
Rough Work for Question 1
Page 2 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
1. How many times “ * “ is displayed? [2 Mark]? Answer: __________3_________
4. How many maximum zombie processes can be created in the above code? [2 Mark]?
Answer: ________________9______
Now, if we re run again and fork tree parent process terminates as the very 1st process after completion.
How many maximum processes can become orphan due to it? [ 2 Marks]
6. Suppose The fork-tree program has just initiated in the new state, and it has been assigned pid as 7542,
as shown below. Complete the Process Tree diagram for the fork-tree process below considering it runs
successfully [5 marks]
All the created processes are direct children of the fork-tree process.
Page 3 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
int main() {
pid_t pid1, pid2, pid3, pid4, pid5;
pid1 = fork();
if (pid1 == 0 || (pid2 = fork()) == 0) {
printf("A\n");
exit(0);
} else {
wait(NULL);
pid3 = fork();
if (pid3 == 0 && (pid4 = fork()) == 0) {
printf("B\n");
exit(0);
} else if (pid3 > 0) {
int s;
waitpid(pid3, &s, 0);
printf("Status of PID3 = %d\n", s);
if ((pid5 = fork()) == 0) {
printf("C\n");
exit(0);
} else {
wait(NULL);
printf("D \n");
return 0;
} } }
return 1;}
Question Answer
Consider removing the last code statement “return 1” from the code snippet provided 4 or 3
above, Number of Zombie Processes [2 Marks]
Page 4 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
Rough Work for Question 2
Page 5 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
Question 3 [Multiple choice questions]
1. Which of the following statements about interrupts A. VMs require a hypervisor to manage hardware
is true? virtualization, while Docker containers leverage operating
A. Interrupt vector tables are used to store addresses of I/O system-level virtualization.
devices only. B. Docker containers provide complete isolation of
B. Interrupts with I/O involve the processor waiting resources, including CPU, memory, and storage, similar
indefinitely for device responses. to VMs.
C. Interrupts with Direct Memory Access (DMA) bypass C. VMs offer superior performance and efficiency
the processor entirely. compared to Docker containers due to their lightweight
D. Interrupts cannot occur during system calls. architecture.
E. None of the above. D. Docker containers share the host operating system
2. Which of the following statements best describes a kernel, enabling faster startup times and reduced resource
limitation of the monolithic kernel architecture? overhead.
A. It provides better isolation between kernel components E. Docker containers are immutable and stateless,
compared to microkernel architectures. whereas VMs support dynamic reconfiguration and state
B. It allows for easy extension and modification of kernel persistence.
functionality without recompilation.
C. It typically results in lower context-switching overhead 5. Which of the following does NOT cause a trap?
compared to microkernel architectures.
A. user program divides a number by zero.
D. It facilitates rapid development of new device drivers
B. The operating system kernel executes a privileged
and file systems due to its highly modular design.
instruction.
E. It tends to have a larger memory footprint due to the
C. A programmable interval timer reaches its specified
inclusion of all operating system services in a single
time.
address space.
D. A user program executes an interrupt instruction.
3. Which of the following statements best describes a
E. None of the above.
key advantage of the microkernel architecture?
A. It offers superior performance in I/O-bound workloads 6. Which of the following components is MOST
compared to monolithic kernel architectures. LIKELY to always be part of the microkernel,
B. It allows for seamless integration of third-party device even in a highly security-focused design?
drivers and file systems without requiring modifications
to the kernel. A. Process scheduling and context switching
C. It enables better real-time responsiveness due to B. Inter-process communication (IPC) mechanisms
reduced context-switching overhead. C. Memory management and protection mechanisms
D. It enhances system security by minimizing the attack D. System call interface and handling
surface exposed by the kernel. E. Basic timer and interrupt handling
E. It simplifies debugging and maintenance by
consolidating all operating system services within the 7. The system receives an interrupt from the disk
kernel space. controller indicating the I/O operation for
process A has finished. Which of the following
4. 4. Which of the following statements best illustrates is most likely to occur first?
a fundamental difference between Docker containers
and Virtual Machines (VMs)? A. Process A's interrupt service routine (ISR) is
immediately executed.
B. The operating system saves the CPU context and
schedules another process.
Page 6 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
C. The operating system updates A's PCB and 11. 11. Which of the following interrupt types most likely
places it in the Ready state. corresponds to each event?
D. The I/O completion notification is sent directly to
process A's code. A. Event 1: Trap, Event 2: System call, Event 3:
E. The interrupt is ignored until process A requests the Abort
I/O data. B. Event 1: Fault, Event 2: Interrupt, Event 3: Abort
C. Event 1: Abort, Event 2: System call, Event 3:
8. Consider a multi-user system implementing five Trap
state process model, currently having five processes: D. Event 1: Exception, Event 2: Trap, Event 3: Fault
A, B, C, D, and E. The current state of the processes E. The provided information is insufficient to
is: determine the exact types.
A. Process A is in the Running state 12. A process stack does not contain:
B. Process B is waiting for an I/O operation (Blocked
state). A. Function parameters
C. Process C is ready to run (Ready state). B. Local variables
D. Process D is newly submitted and needs resources
C. Return addresses
allocated (New state).
E. Process E is finished execution and waiting for its D. PID of child process
resources to be reclaimed (Terminated state). E. PID of itself
9. In a Process Control Block (PCB), which of the 13. How is modularity added to the Linux kernel
following data elements is LEAST LIKELY to be that is typically a monolithic kernel:
found?
A. By adding more system calls
A. Open Files Table B. Through loadable modules
B. Program Counter (PC) C. By adopting micro-kernel approach in Linux
C. Register Values D. Both a and b
D. Complete source code
E. Memory Layout information (e.g., stack base, heap 14. In the five-state model why would a process
limits) move from Running to Ready state?
10. The system receives an interrupt from the disk A. The process has terminated
controller indicating the I/O operation for process A B. The process needs to perform an I/O operation
has finished. Which of the following is most likely to C. The process’ time quantum has expired
occur first? D. The process needs to execute a system call
Page 7 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
16. Multiprogramming is: 21. When a process is first launched, the operating
system does not know the size of this segment:
A. An executable program that is composed of modules
built using different programming languages. A. text
B. Keeping several programs in memory at once and B. data
switching between them. C. bss
C. Having multiple processors execute different programs D. heap
at the same time.
D. When a program has multiple threads that run 22. Which of the option arranges the following
concurrently technologies in the order from fastest to
slowest:
17. A process control block is:
A. Hard-disk drives, main memory, cache, registers
A. A structure that stores information about a single B. Registers, main memory, hard-disk drives, cache
process. C. Registers, cache, main memory, hard-disk drives
B. The kernel's structure for keeping track of all the D. Cache, registers, main memory, hard-disk drives
processes in the system.
C. A linked list of blocked processes (those waiting on 23. You are a software developer working on the
some event). next generation of a popular smartphone
D. A kernel interface for controlling processes (creating, operating system. The phone needs to be
deleting, suspending). powerful, secure, and energy-efficient. Which
of the following factors is most likely to favor a
18. Which state transition is not valid? microkernel architecture for this smartphone
operating system?
A. Ready → Blocked
B. Running → Ready A. The need for extensive customization of the
C. Ready → Running operating system for specific user needs.
D. Running → Blocked B. The requirement for real-time performance for
latency-sensitive applications like gaming.
19. Preemption is when an operating system moves a C. The desire to leverage the latest hardware features
process between these states: for maximum processing power.
D. The need for strong security features to protect
A. Running → Blocked user data and privacy.
B. Running → Ready E. The goal of achieving the longest possible battery
C. Ready → Blocked life for the smartphone.
D. Blocked → Running
Page 8 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
C. Becomes an orphan process, detached from the parent 28. 28. From a user point of view, which component of an
but still running. operating system directly interacts with the user,
D. Enters a zombie state, lingering until explicitly reaped. allowing them to issue commands and run
E. None of the options seems to be valid in this case. applications?
Page 9 of 10
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
MCQS SOLUTION
1 C 16 B
2 E 17 A
3 D 18 A
4 A 19 B
5 B 20 D
6 C 21 D
7 C 22 C
8 E 23 D
9 D 24 C
10 C 25 B
11 B 26 A
12 D 27 C
13 B 28 B
14 C 29 C
15 C 30 A
Page 10 of 10