0% found this document useful (0 votes)
27 views

MidTerm (Solution) - 5A

Uploaded by

Faizan Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

MidTerm (Solution) - 5A

Uploaded by

Faizan Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Midterm

COMSATS INSTITUTE OF INFORMATION TECHNOLOGY


Department of Electrical and Computer Engineering
Islamabad campus
BCE 5-A

Course title: Operating Systems (CSC322)


Course Instructor: Dr. Omair Inam
Date: handed out: 14 November 2022
Time: 14:30 – 15:50
Total Marks: 50

Q1
a) Name the six main function of kernel in OS? (6 Marks)
Solution:
• scheduling processes
• resource allocation
• device management
• interrupt handling
• memory management
• process management.

b) What are the three cases when the control must transfer the from
user program to the kernel (5 Marks)
Solution:
1) First, a system call: when a user program asks for an operating
system service,
2) Second, an exception: when a program per- forms an illegal
action. Examples of illegal actions include divide by zero, attempt
to access memory for a PTE that is not present, and so on.
3) Third, an interrupt: when a device generates a signal to indicate
that it needs attention from the operating system. For example,
a clock chip may generate an interrupt every 100 msec to allow
the ker- nel to implement time sharing. As another example,
when the disk has read a block from disk, it generates an
interrupt to alert the operating system that the block is ready to
be retrieved.

c) What is the difference between multiprogramming OS and time-


sharing OS (5 Marks)
Solution:
Multi-Programming OS Time-Sharing OS
Multiprogramming operating system Time-Sharing is the logical extension of
allows executing multiple processes by multiprogramming. In this time-sharing
monitoring their process states and Operating system, many users/processes
switching between processes. are allocated with computer resources in
respective time slots
The processor and memory The processor's time is shared with
underutilization problem is resolved, and multiple users. That's why it is called a
multiple programs run on the CPU. That's time-sharing operating system.
why it is called multiprogramming.

In multiprogramming, the process can be In this process, two or more users can use
executed by a single processor. a processor in their terminal.
Multiprogramming OS has no fixed time Time-sharing OS has a fixed time slice.
slice

In Multiprogramming OS, the system In time-sharing, the OS system depends


depends on devices to switch between on time to switch between different
tasks such as I/O interrupts. processes.

The system model of a multiprogramming A system model of the time-sharing


system is multiple programs.Example: system is multiple programs and multiple
Mac OS, Window OS, microcomputers users.Example: Windows NT server, Unix,
such as MP/M, XENIX, and ESQview Linux, Multics, TOPS-10, TOPS-20

d) Name the system calls in the following table. (4 Marks)

Windows Unix

Process control CreatProcess() fork()

File Manipulation CreatFile() open()

e) Name the five advantages of layered operating system. (5 Marks)


Solution:

1. Modularity
2. Easy Debugging
3. Easy Update
4. No direct access to hardware
5. Abstraction
Q2 a) With the help of a diagram, show the steps involve in the process of
context switching between two process P1 and P2. (10 Marks)
Solution

b) Consider the following code segment: (15 Marks)

#include <stdio.h>
#include <unistd.h>
int main()
{
if (fork() || fork())
fork();
printf(" print ");
return 0;
}

a. Show with the help of a diagram that how many process are created?

b. what will be the output of the program?

Solution

print print print print print


Explanation:
1. It will create two process one parent P (has process ID of child process)and
other is child C1 (process ID = 0).
2. In if statement we used OR operator( || ) and in this case second condition is
evaluated when first condition is false.
3. Parent process P will return positive integer so it directly execute statement
and create two more processes (one parent P and other is child C2). Child
process C1 will return 0 so it checks for second condition and second condition
again create two more processes(one parent C1 and other is child C3).
4. C1 return positive integer so it will further create two more processes (one
parent C1 and other is child C4). Child C3 return 0 so it will directly print.

You might also like