0% found this document useful (0 votes)
35 views10 pages

OS-SESSIONAL 1 SOLUTION

The document outlines the exam instructions and questions for the CS-2006: Operating Systems course at the National University of Computer and Emerging Sciences. It includes details on the exam format, rules for answering questions, and specific programming tasks related to process creation and management in C. Additionally, it features multiple-choice questions on operating system concepts, emphasizing process control and interrupt handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views10 pages

OS-SESSIONAL 1 SOLUTION

The document outlines the exam instructions and questions for the CS-2006: Operating Systems course at the National University of Computer and Emerging Sciences. It includes details on the exam format, rules for answering questions, and specific programming tasks related to process creation and management in C. Additionally, it features multiple-choice questions on operating system concepts, emphasizing process control and interrupt handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

National University of Computer and Emerging Sciences

FAST School of Computing Spring 24 Islamabad Campus

CS-2006: Operating Systems Serial No:


Monday, 26 February, 2024 Sessional 1
Course Instructors Total Time: 1 Hour
Dr. Faisal Cheema, Dr. Adnan Tariq, Miss. Maryam Total Marks: 60 Marks
Shahbaz, Miss Rabail , Mr. M. Adil ur Rehman
________________
Signature of Invigilator

____________________ ____________ _____________ __________________


Student Name Roll No. Course Section Student Signature

DO NOT OPEN THE QUESTION BOOK OR START UNTIL INSTRUCTED.

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.

Q-1 Q-2 Q-4 Total


Marks
Obtained
Total
15 15 30 60
Marks
National University of Computer and Emerging Sciences
FAST School of Computing Spring 24 Islamabad Campus
HONEST 0 is BETTER THAN DISHONEST A+
Question 1 [15 marks]

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_________

2. How many times “ + “ is displayed? [2 Mark]? Answer: _________6__________

3. How many times “ # “ is displayed? [2 Mark]? Answer:_________1___________

4. How many maximum zombie processes can be created in the above code? [2 Mark]?

Answer: ________________9______

5. Suppose the following lines are removed from the code:

for (int k=0;k<2;k++)


wait( NULL) ;

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]

Answer: _____all chILDREN_____________________

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.

Question 2 [10 Marks ]


Analyze the program by drawing process tree and dry run in the rough space provided. Then answer the
questions provided in the table below. No answer will be accepted without the matching rough work
according to these instructions.
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

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

Total number of Processes created including the main process [6 Marks] 7


Number of Zombie Processes [3 Marks] 3
How many times B will be printed? [2 Marks] 1
Consider removing the last code statement “return 1” from the code snippet provided Status of
above, What would be changed in the output? [2 Marks] PID=Garbage
(maybe 0) or main
process would be
waiting indfinitely

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

15. 15. A zombie process is a process that has


A. Process A's interrupt service routine (ISR) is immediately
executed. terminated and
B. The operating system saves the CPU context and
schedules another process. A. Its parent process has also terminated without
C. The operating system updates A's PCB and applying the wait system call
places it in the Ready state. B. The parent process is currently executing without
D. The I/O completion notification is sent directly to applying the wait system call
process A's code. C. The parent process is currently executing without
E. The interrupt is ignored until process A requests applying the exit system call
the I/O data. D. It was created without any parent
E. None of these

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

20. With DMA (Direct Memory Access):


24. 24. Your program forks a child process to perform a
A. The processor can read or write directly to a device. long-running task (i.e., longer than parent).
B. The kernel can read or write directly to a process’ However, you forget to wait for the child process to
memory without intermediate buffers. terminate and continue with your program's
C. A process can read or write to kernel memory execution. What would happen to the child process?
without intermediate buffers.
D. The device can read or write directly to the A. Running normally, unaffected by the parent process.
system’s memory B. Terminated immediately as it cannot be executed
without a parent

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?

25. A device driver runs on the microcontroller that is A. Kernel


part of the external device B. Shell
C. Scheduler
A. True D. File System
B. False 29. From a system perspective, which of the following
C. Depends on the device architecture tasks is typically not a responsibility of the operating
system?
26. When interacting with a fast device, it can be better
A. Managing memory allocation and deallocation
to spin wait than to use interrupts.
B. Scheduling processes for execution
A. True C. Providing a graphical user interface (GUI)
B. False D. Handling file system operations
C. I/O devices cannot be fast
30. During the boot process of a computer system,
27. What is the primary purpose of a system call in an
what is the first program that is loaded into
operating system?
memory and executed by the CPU?
A. To execute user-level applications
B. To allow communication between different processes A. BIOS (Basic Input/Output System)
C. To request services from the operating system kernel B. Operating System Kernel
D. To manage hardware resources C. Bootloader
D. Device Drivers

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

You might also like