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

OS Unit 1 Answer Key

Uploaded by

saitejakasani091
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)
47 views

OS Unit 1 Answer Key

Uploaded by

saitejakasani091
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/ 21

Operating Systems

Unit 1
1) a) Define an operating system? (2 mark)

Operating System lies in the category of system software. It basically manages all the
resources of the computer. An operating system acts as an interface between the
software and different parts of the computer or the computer hardware. The operating
system is designed in such a way that it can manage the overall resources and
operations of the computer.
Operating System is a fully integrated set of specialized programs that handle all the
operations of the computer. It controls and monitors the execution of all other programs
that reside in the computer, which also includes application programs and other system
software of the computer. Examples of Operating Systems are Windows, Linux, Mac
OS, etc.
An Operating System (OS) is a collection of software that manages computer hardware
resources and provides common services for computer programs. The operating system
is the most important type of system software in a computer system.

b) State and explain the basic functions or services of an operating system? (6 mark)

1. Program execution
2. I/O operations
3. File system manipulation
4. Communication
5. Error detection
6. Resource allocation
7. Protection
1) Program Execution: An operating system must be able to load many kinds of activities
into the memory and to run it. The program must be able to end its execution, either normally
or abnormally. A process includes the complete execution of the written program or code.
There are some of the activities which are performed by the operating system: The operating
system loads program into memory. It also executes the program. It handles the program’s
execution. It provides a mechanism for process synchronization. It provides a mechanism for
process communication

2) I/O Operations: The communication between the user and devices drivers are managed
by the operating system. I/O devices are required for any running process. In I/O a file or an
I/O devices can be involved. I/O operations are the read or write operations which are done
with the help of input-output devices. Operating system give the access to the I/O devices
when it required.

3) File system manipulation: The collection of related information which represent some
content is known as a file. The computer can store files on the secondary storage devices. For
long-term storage purpose. examples of storage media include magnetic tape, magnetic disk
and optical disk drives like CD, DVD. A file system is a collection of directories for easy
understand and usage. These directories contain some files. There are some major activities
which are performed by an operating system with respect to file management. The operating
system gives an access to the program for performing an operation on the file. Programs need
to read and write a file. The user can create/delete a file by using an interface provided by the
operating system. The operating system provides an interface to the user creates/ delete
directories. The backup of the file system can be created by using an interface provided by
the operating system.

4) Communication: In the computer system, there is a collection of processors which do not


share memory peripherals devices or a clock, the operating system manages communication
between all the processes. Multiple processes can communicate with every process through
communication lines in the network. There are some major activities that are carried by an
operating system with respect to communication. Two processes may require data to be
transferred between the process. Both the processes can be on one computer or a different
computer, but are connected through a computer network.

5) Error handling: An error is one part of the system that may cause malfunctioning of the
complete system. The operating system constantly monitors the system for detecting errors to
avoid some situations. This give relives to the user of the worry of getting an error in the
various parts of the system causing malfunctioning. The error can occur anytime and
anywhere. The error may occur anywhere in the computer system like in CPU, in I/O devices
or in the memory hardware. There are some activities that are performed by an operating
system: The OS continuously checks for the possible errors. 12 The OS takes an appropriate
action to correct errors and consistent computing.

6) Resource management: When there are multiple users or multiple jobs running at the
same time resources must be allocated to each of them. There are some major activities that
are performed by an operating system: The OS manages all kinds of resources using
schedulers. CPU scheduling algorithm is used for better utilization of CPU.

7) Protection: The owners of information stored in a multi-user computer system want to


control its use. When several disjoints processes execute concurrently it should not be
possible for any process to interfere with another process. Every process in the computer
system must be secured and controlled.

2) Identify various types of Operating System Components. (8 marks)

1. File management
2. Process management
3. I/O device management
4. Network management
5. Secondary storage management
6. Security management
1. File management:

Files are used for long-term storage. Files are used for both input and output. Every
operating system provides a file management service. This file management service can
also be treated as an abstraction as it hides the information about the disks from the user.
The operating system also provides a system call for file management. The system call for
file management includes –
 File creation
 File deletion
 Read and Write operations
Files are stored in a directory. System calls provide to put a file in a directory or to remove
a file from a directory. Files in the system are protected to maintain the privacy of the user.
2. Process management:

A process is a program in execution. It consists of the followings:

 Executable program
 Program’s data
 Stack and stack pointer
 Program counter and other CPU registers
 Details of opened files
A process can be suspended temporarily and the execution of another process can be taken
up. A suspended process can be restarted later. Before suspending a process, its details are
saved in a table called the process table so that it can be executed later on. An operating
system supports two system calls to manage processes Create and Kill –
 Create a system call used to create a new process.
 Kill system call used to delete an existing process.
A process can create a number of child processes. Processes can communicate among
themselves either using shared memory or by message-passing techniques. Two processes
running on two different computers can communicate by sending messages over a network.
3. I/O device management:

The I/O device management component is an I/O manager that hides the details of hardware
devices and manages the main memory for devices using cache and spooling. This
component provides a buffer cache and general device driver code that allows the system to
manage the main memory and the hardware devices connected to it. It also provides and
manages custom drivers for particular hardware devices. The purpose of the I/O system is to
hide the details of hardware devices from the application programmer. An I/O device
management component allows highly efficient resource utilization while minimizing errors
and making programming easy on the entire range of devices available in their systems.

4. Network management:

In today’s digital world, the complexity of networks and services has created modern
challenges for IT professionals and users. Network management is a set of processes and
procedures that help organizations to optimize their computer networks. Mainly, it ensures
that users have the best possible experience while using network applications and services.
Network management is a fundamental concept of computer networks. Network
Management Systems is a software application that provides network administrators with
information on components in their networks. It ensures the quality of service and
availability of network resources. It also examines the operations of a network, reconstructs
its network configuration, modifies it for improving performance of tasks.
5. Secondary storage management:

Broadly, the secondary storage area is any space, where data is stored permanently and the
user can retrieve it easily. Your computer’s hard drive is the primary location for your files
and programs. Other spaces, such as CD-ROM/DVD drives, flash memory cards, and
networked devices, also provide secondary storage for data on the computer. The computer’s
main memory (RAM) is a volatile storage device in which all programs reside, it provides
only temporary storage space for performing tasks. Secondary storage refers to the media
devices other than RAM (e.g. CDs, DVDs, or hard disks) that provide additional space for
permanent storing of data and software programs which is also called non-volatile storage.

6. Security management:

The security mechanisms in an operating system ensure that authorized programs have
access to resources, and unauthorized programs have no access to restricted resources.
Security management refers to the various processes where the user changes the file,
memory, CPU, and other hardware resources that should have authorization from the
operating system.

3) A) Sketch the structure of operating system with its different layers? (2 mark)

B) Explain different types of operating systems? (6 mark)

Given below are different types of Operating System:


1. Simple Batch System
2. Multi programmed
3. Time-Shared
4. Personal Computer
5. Parallel
6. Distributed Systems
7. Real Time Systems

1. Simple Batch System:

In a Batch Operating System, the similar jobs are grouped together into batches with the help
of some operator and these batches are executed one by one. For example, let us assume that
we have 10 programs that need to be executed. Some programs are written in C++, some in C
and rest in Java. Now, every time when we run these programmes individually then we will
have to load the compiler of that particular language and then execute the code. But what if
we make a batch of these 10 programmes. The benefit with this approach is that, for the C++
batch, you need to load the compiler only once. Similarly, for Java and C, the compiler needs
to be loaded only once and the whole batch gets executed. The following image describes the
working of a Batch Operating System.

Advantages:

 The overall time taken by the system to execute all the programmes will be reduced.
 The Batch Operating System can be shared between multiple users.

Disadvantages:

 Manual interventions are required between two batches.


 The CPU utilization is low because the time taken in loading and unloading of batches
is very high as compared to execution time.

2. Multi programmed:
Sharing the processor, when two or more programs reside in memory at the same time, is
referred as multiprogramming. Multiprogramming assumes a single shared processor.
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
one to execute. The following figure shows the memory layout for a multiprogramming
system.
An OS does the following activities related to multiprogramming. The operating system keeps
several jobs in memory at a time. This set of jobs is a subset of the jobs kept in the job pool.
The operating system picks and begins to execute one of the jobs in the memory.
Multiprogramming operating systems monitor the state of all active programs and system
resources using memory management programs to ensures that the CPU is never idle, unless
there are no jobs to process.

Advantages:

 High and efficient CPU utilization.


 User feels that many programs are allotted CPU almost simultaneously.

Disadvantages:

 CPU scheduling is required.


 To accommodate many jobs in memory, memory management is required.

3. Time-Shared:
In a Multi-tasking Operating System, more than one process are being executed at a particular
time with the help of the time-sharing concept. So, in the time-sharing environment, we decide
a time that is called time quantum and when the process starts its execution then the execution
continues for only that amount of time and after that, other processes will be given chance for
that amount of time only. In the next cycle, the first process will again come for its execution
and it will be executed for that time quantum only and again next process will come. This
process will continue. The following image describes the working of a Time-Sharing
Operating System.

Advantages:
1. Since equal time quantum is given to each process, so each process gets equal opportunity to
execute.
2. The CPU will be busy in most of the cases and this is good to have case.
Disadvantages:
1. Process having higher priority will not get the chance to be executed first because the equal
opportunity is given to each process

4. Personal Computer:
Personal computer operating system provides a good interface to a single user. Personal
computer operating systems are widely used for word processing, spread sheets and Internet
access. Personal computer operating system are made only for personal. You can say that your
laptops, computer systems, tablets etc. are your personal computers and the operating system
such as windows 7, windows 10, android, etc. are your personal computer operating system.
And you can use your personal computer operating system for your personal purposes, for
example, to chatting with your friends using some social media sites, reading some articles
from internet, making some projects through Microsoft PowerPoint or any other, designing
your website, programming something, watching some videos and movies, listening to some
songs and many more.

5. Parallel Processing:

Parallel processing requires multiple processors and all the processor works simultaneously in
the system. Here, the task is divided into subparts and these subparts are then distributed
among the available processors in the system. Parallel processing completes the job on the
shortest possible time. All the processors in the parallel processing environment should run on
the same operating system. All processors here are tightly coupled and are packed in one
casing. All the processors in the 6 system share the common secondary storage like the hard
disk. As this is the first place where the programs are to be placed. There is one more thing that
all the processors in the system share i.e. the user terminal (from where the user interact with
the system). The user need not to be aware of the inner architecture of the machine. He should
feel that he is dealing with the single processor only and his interaction with the system would
be the same as in a single processor

Advantages:

1. It saves time and money as many resources working together will reduce the time and cut
potential costs.
2. It can be impractical to solve larger problems on Serial Computing.
3. It can take advantage of non-local resources when the local resources are finite.
4. Serial Computing ‘wastes’ the potential computing power, thus Parallel Computing makes
better work of the hardware.
Disadvantages:
1. It addresses such as communication and synchronization between multiple sub-tasks and
processes which is difficult to achieve.
2. The algorithms must be managed in such a way that they can be handled in a parallel
mechanism.
3. The algorithms or programs must have low coupling and high cohesion. But it’s difficult to
create such programs.
4. More technically skilled and expert programmers can code a parallelism-based program
well.
6. Distributed Operating System:

These types of the operating system are a recent advancement in the world of computer
technology and are being widely accepted all over the world and, that too, with a great pace.
Various autonomous interconnected computers communicate with each other using a shared
communication network. Independent systems possess their own memory unit and CPU.
These are referred to as loosely coupled systems or distributed systems. These system’s
processors differ in size and function. The major benefit of working with these types of the
operating system is that it is always possible that one user can access the files or software
which are not actually present on his system but some other system connected within this
network i.e., remote access is enabled within the devices connected in that network.

Advantages:

 Failure of one will not affect the other network communication, as all systems are
independent from each other
 Electronic mail increases the data exchange speed
 Since resources are being shared, computation is highly fast and durable
 Load on host computer reduces
 These systems are easily scalable as many systems can be easily added to the network
 Delay in data processing reduces
Disadvantages:

 Failure of the main network will stop the entire communication


 To establish distributed systems the language which is used are not well defined yet
 These types of systems are not readily available as they are very expensive.
7. Real Time Systems:
It is developed for real-time applications where data should be processed in a fixed, small
duration of time. It is used in an environment where multiple processes are supposed to be
accepted and processed in a short time. RTOS requires quick input and immediate response,
e.g., in a petroleum refinery, if the temperate gets too high and crosses the threshold value,
there should be an immediate response to this situation to avoid the explosion. Similarly, this
system is used to control scientific instruments, missile launch systems, traffic lights control
systems, air traffic control systems, etc. This system is further divided into two types based
on the time constraints: Hard Real-Time Systems: These are used for the applications where
timing is critical or response time is a major factor; even a delay of a fraction of the second
can result in a disaster. For example, airbags and automatic parachutes that open instantly in
case of an accident. Besides this, these systems lack virtual memory. Soft Real-Time
Systems: These are used for application where timing or response time is less critical. Here,
the failure to meet the deadline may result in a degraded performance instead of a disaster.
For example, video surveillance (cctv), video player, virtual reality, etc. Here, the deadlines
are not critical for every task every time.

Advantages: The output is more and quick owing to the maximum utilization of devices and
system. Task shifting is very quick, e.g., 3 microseconds, due to which it seems that several
tasks are executed simultaneously. Gives more importance to the currently running
applications than the queued application. It can be used in embedded systems like in transport
and others. It is free of errors. Memory is allocated appropriately.

Disadvantages: A fewer number of tasks can run simultaneously to avoid errors. It is not
easy for a designer to write complex and difficult algorithms or proficient programs required
to get the desired output. Specific drivers and interrupt signals are required to respond to
interrupts quickly. It may be very expensive due to the involvement of the resources required
to work.

4. Elaborate the following:


A) Simple Batch Systems, Multi Programmed Systems. (4 marks)

1. Simple Batch System:

In a Batch Operating System, the similar jobs are grouped together into batches with the help
of some operator and these batches are executed one by one. For example, let us assume that
we have 10 programs that need to be executed. Some programs are written in C++, some in C
and rest in Java. Now, every time when we run these programmes individually then we will
have to load the compiler of that particular language and then execute the code. But what if
we make a batch of these 10 programmes. The benefit with this approach is that, for the C++
batch, you need to load the compiler only once. Similarly, for Java and C, the compiler needs
to be loaded only once and the whole batch gets executed. The following image describes the
working of a Batch Operating System.

Advantages:

 The overall time taken by the system to execute all the programmes will be reduced.
 The Batch Operating System can be shared between multiple users.

Disadvantages:

 Manual interventions are required between two batches.


 The CPU utilization is low because the time taken in loading and unloading of batches
is very high as compared to execution time.

2. Multi programmed:
Sharing the processor, when two or more programs reside in memory at the same time, is
referred as multiprogramming. Multiprogramming assumes a single shared processor.
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
one to execute. The following figure shows the memory layout for a multiprogramming
system.

An OS does the following activities related to multiprogramming. The operating system keeps
several jobs in memory at a time. This set of jobs is a subset of the jobs kept in the job pool.
The operating system picks and begins to execute one of the jobs in the memory.
Multiprogramming operating systems monitor the state of all active programs and system
resources using memory management programs to ensures that the CPU is never idle, unless
there are no jobs to process.
Advantages:

 High and efficient CPU utilization.


 User feels that many programs are allotted CPU almost simultaneously.

Disadvantages:

 CPU scheduling is required.


 To accommodate many jobs in memory, memory management is required.
B) Time Shared Systems, Real Time Systems, Distributed Operating Systems. (4 marks)

1. Time-Shared:
In a Multi-tasking Operating System, more than one processes are being executed at a
particular time with the help of the time-sharing concept. So, in the time-sharing environment,
we decide a time that is called time quantum and when the process starts its execution then the
execution continues for only that amount of time and after that, other processes will be given
chance for that amount of time only. In the next cycle, the first process will again come for its
execution and it will be executed for that time quantum only and again next process will come.
This process will continue. The following image describes the working of a Time-Sharing
Operating System.

Advantages:
1. Since equal time quantum is given to each process, so each process gets equal opportunity to
execute.
2. The CPU will be busy in most of the cases and this is good to have case.

Disadvantages:
1. Process having higher priority will not get the chance to be executed first because the equal
opportunity is given to each process

2. Real Time Systems:

It is developed for real-time applications where data should be processed in a fixed, small
duration of time. It is used in an environment where multiple processes are supposed to be
accepted and processed in a short time. RTOS requires quick input and immediate response,
e.g., in a petroleum refinery, if the temperate gets too high and crosses the threshold value,
there should be an immediate response to this situation to avoid the explosion. Similarly, this
system is used to control scientific instruments, missile launch systems, traffic lights control
systems, air traffic control systems, etc. This system is further divided into two types based on
the time constraints: Hard Real-Time Systems: These are used for the applications where
timing is critical or response time is a major factor; even a delay of a fraction of the second can
result in a disaster. For example, airbags and automatic parachutes that open instantly in case
of an accident. Besides this, these systems lack virtual memory. Soft Real-Time Systems:
These are used for application where timing or response time is less critical. Here, the failure
to meet the deadline may result in a degraded performance instead of a disaster. For example,
video surveillance (cctv), video player, virtual reality, etc. Here, the deadlines are not critical
for every task every time.

Advantages:

The output is more and quick owing to the maximum utilization of devices and system. Task
shifting is very quick, e.g., 3 microseconds, due to which it seems that several tasks are
executed simultaneously. Gives more importance to the currently running applications than
the queued application. It can be used in embedded systems like in transport and others. It is
free of errors. Memory is allocated appropriately.

Disadvantages:

A fewer number of tasks can run simultaneously to avoid errors. It is not easy for a designer
to write complex and difficult algorithms or proficient programs required to get the desired
output. Specific drivers and interrupt signals are required to respond to interrupts quickly. It
may be very expensive due to the involvement of the resources required to work.

3. Distributed Operating System:

These types of the operating system are a recent advancement in the world of computer
technology and are being widely accepted all over the world and, that too, with a great pace.
Various autonomous interconnected computers communicate with each other using a shared
communication network. Independent systems possess their own memory unit and CPU.
These are referred to as loosely coupled systems or distributed systems. These system’s
processors differ in size and function. The major benefit of working with these types of the
operating system is that it is always possible that one user can access the files or software
which are not actually present on his system but some other system connected within this
network i.e., remote access is enabled within the devices connected in that network.
Advantages:

 Failure of one will not affect the other network communication, as all systems are
independent from each other
 Electronic mail increases the data exchange speed
 Since resources are being shared, computation is highly fast and durable
 Load on host computer reduces
 These systems are easily scalable as many systems can be easily added to the network
 Delay in data processing reduces
Disadvantages:

 Failure of the main network will stop the entire communication


 To establish distributed systems the language which is used are not well defined yet
 These types of systems are not readily available as they are very expensive.

5. Illustrate Round Robin and Priority scheduling algorithm with suitable examples.
(8 marks)

Round Robin algorithm:


It is designed especially for time sharing systems. Here CPU switches between the processes.
When the time quantum expired, the CPU switched to another job. A small unit of time,
called a time quantum or time slice. A time quantum is generally from 10 to 100 ms. The
time quantum is generally depending on OS. Here ready queue is a circular queue. CPU
scheduler picks the first process from ready queue, sets timer to interrupt after one time
quantum and dispatches the process.

AVERAGE WAITING TIME :

Waiting time for P1 => 0+(15-5)+(24-20) => 0+10+4 = 14


Waiting time for P2 => 5+(20-10) => 5+10 = 15
Waiting time for P3 => 10+(21-15) => 10+6 = 16
Average waiting time => (14+15+16)/3 = 15 ms.
AVERAGE TURN AROUND TIME :

FORMULA : Turn around time = waiting time + burst Time


Turn around time for P1 => 14+30 =44
Turn around time for P2 => 15+6 = 21
Turn around time for P3 => 16+8 = 24
Average turn around time => ( 44+21+24 )/3 = 29.66 ms

PRIORITY SCHEDULING:

AVERAGE WAITING TIME:

Waiting time for P1 => 3-0 =3


Waiting time for P2 => 13-0 = 13 Waiting time for P3 => 25-0 = 25
Waiting time for P4 => 0
Waiting time for P5 => 9-0 =9 25
Average waiting time => ( 3+13+25+0+9 )/5 = 10 ms

AVERAGE TURN AROUND TIME :

Turn around time for P1 =>3+6 = 9 Turn around time for P2 => 13+12= 25
Turn around time for P3 => 25+1 = 26
Turn around time for P4 => 0+3= 3
Turn around time for P5 => 9+4 = 13 Average
Turn around time => ( 9+25+26+3+13 )/5 = 15.2 ms

6. Determine various Preemptive Scheduling Algorithms with examples. (8 mark)


Round Robin algorithm:
It is designed especially for time sharing systems. Here CPU switches between the processes.
When the time quantum expired, the CPU switched to another job. A small unit of time,
called a time quantum or time slice. A time quantum is generally from 10 to 100 ms. The
time quantum is generally depending on OS. Here ready queue is a circular queue. CPU
scheduler picks the first process from ready queue, sets timer to interrupt after one time
quantum and dispatches the process.
AVERAGE WAITING TIME :
Waiting time for P1 => 0+(15-5)+(24-20) => 0+10+4 = 14
Waiting time for P2 => 5+(20-10) => 5+10 = 15
Waiting time for P3 => 10+(21-15) => 10+6 = 16
Average waiting time => (14+15+16)/3 = 15 ms.
AVERAGE TURN AROUND TIME :
FORMULA : Turn around time = waiting time + burst Time
Turn around time for P1 => 14+30 =44
Turn around time for P2 => 15+6 = 21
Turn around time for P3 => 16+8 = 24
Average turn around time => ( 44+21+24 )/3 = 29.66 ms

Shortest Remaining Time First (SRTF):

This is primitive scheduling algorithm. Short term scheduler always chooses the process that
has term shortest remaining time. When a new process joins the ready queue, short term
scheduler compare the remaining time of executing process and new process. If the new
process has the least CPU burst time, The scheduler selects that job and connect to CPU.
Otherwise continue the old process.

P1 arrives at time 0, P1 executing First , P2 arrives at time 2. Compare P1 remaining time and
P2 ( 3-2 = 1) and 6. So, continue P1 after P1, executing P2, at time 4, P3 arrives, compare P2
remaining time (6-1=5 ) and 4(4<5). So, executing P3 at time 6, P4 arrives. Compare P3
remaining time and P4 ( 4- 2=2 ) and 5 (2<5) So, continue P3 , after P3, ready queue consisting
P5 is the least out of three. So execute P5, next P2, P4.

Formula: Finish time – Arrival Time


Finish Time for P1 => 3-0 = 3
Finish Time for P2 => 15-2 = 13
Finish Time for P3 => 8-4 =4
Finish Time for P4 => 20-6 = 14
Finish Time for P5 => 10-8 = 2
Average Turn around time => 36/5 = 7.2 ms.

7.Assume the following workload in a system. All jobs arrive at time 0 in the ordergiven.
Process Burst time Priority

P1 9 5

P2 4 3

P3 5 1

P4 7 2

P5 3 4

Draw a Gantt chart illustrating the execution of these jobs using Priority CPU
scheduling algorithm and also Calculate the average waiting time and average
turnaround time. (8 marks)
Soln:

P3 P4 P2 P5 P1

0 5 12 16 19 28
Here, Arrival Time (AT) = 0
Turn Around Time (TAT) = Completion Time (CT) – Arrival Time (AT)
TAT (P1) = 28 – 0 = 28
TAT (P2) = 16 – 0 = 16
TAT (P3) = 5 – 0 = 5
TAT (P4) = 12 – 0 = 12
TAT (P5) = 19 – 0 = 19
Average Turn Around Time = (28+16+5+12+19) / 5 = 80 / 5 = 16
Waiting time (WT) = Turn around Time – Burst time
WT (P1) = 28 – 9 = 28
WT (P2) = 16 – 4 = 12
WT (P3) = 5 – 5 = 0
WT (P4) = 12 – 7 = 5
WT (P5) = 19 – 3 = 16
Average waiting Time = (19=12+0+5+16) / 5 = 52 / 5 = 10.4
8) What is a Thread? Explain about types of Threads. (8 marks)
A Thread is a flow of execution through the process code, with its own program counter
that keeps track of which instruction to execute next, system registers which hold its
current working variables, and a stack which contains the execution history.
 A thread is also called a lightweight process.
 So far, process has a single thread of execution
 Consider having multiple program counters per process
 Multiple locations can execute at once
 Multiple threads of control -> threads
 Must then have storage for thread details, multiple program counters in PCB
Advantages of Threads:
 Threads minimize the context switching time.
 Use of threads provides concurrency within a process.
 Efficient communication.
 It is more economical to create and context switch threads.
 Threads allow utilization of multiprocessor architectures to a greater scale and
efficiency.
Types of Threads:
Threads are implemented in following two ways:
 User Level Threads - User managed threads
 Kernel Level Threads - Operating System managed threads acting on kernel, an
operating system core.
User Level Threads:
 Thread management kernel is not aware of the existence of threads.
 The thread library contains code for creating and destroying threads, for passing
message and data between threads, for scheduling thread execution and for saving
and restoring thread contexts.
 The application starts with a single thread.
Advantages:
 Thread switching does not require Kernel mode privileges.
 User level thread can run on any operating system.
 Scheduling can be application specific in the user level thread.
 User level threads are fast to create and manage.
Disadvantages:
 In a typical operating system, most system calls are blocking.
 Multithreaded application cannot take advantage of multiprocessing.
Kernel Level Threads:
 Thread management is done by the Kernel.
 There is no thread management code in the application area.
 Kernel threads are supported directly by the operating system. Any application can
be programmed to be multithreaded.
 All of the threads within an application are supported within a single process.
Advantages:
 Kernel can simultaneously schedule multiple threads from the same process on
multiple processes.
 If one thread in a process is blocked, the Kernel can schedule another thread of the
same process.
 Kernel routines themselves can be multithreaded.
Disadvantages:
 Kernel threads are generally slower to create and manage than the user threads.
 Transfer of control from one thread to another within the same process requires a
mode switch to the Kernel.

9) Analyze the following:


A) Process (2 mark)
B) Process Control Block (2 mark)
C) Process Life Cycle (4 mark)
Answer:
A) Process:
In an operating system, a process is an instance of a program in execution. It is a basic unit of
work that can be scheduled and executed by the operating system.
The components of a process are:
 Program code/Text: The instructions that the process will execute.
 Data: The data that the process will use during its execution.
 Stack: A data structure that is used to store temporary data, such as function parameters and
return addresses.
 Heap: A data structure that is used to store dynamically allocated memory.
 Process control block (PCB): A data structure that contains information about the process,
such as its state, priority, and memory usage.
B) Process Control block:
An OS serves in the creation, scheduling and termination of processes. The OS consists of
Process Control Block (PCB) that helps control the functioning of processes. Every process
in OS has a PCB associated with it. A PCB keeps track of processes by storing information
about various things like their state, I/O status and CPU Scheduling. Understanding the
components of a PCB will help us get to know the process information better. A PCB
comprises of the following:
1. Process ID: An identifier that helps us in identifying and locating a process.
2. Process state: It identifies the state that the process is currently in. It could be a new
process, ready, running, waiting or terminated.
3. Program counter: It holds the address of the next instruction to be executed for the process.
It also stores a count of the number of instructions in the process.
4. CPU registers: The content of processor registers gets stored here when the process is in
running state. The different kinds of CPU registers are accumulators, index and general-
purpose registers, instruction register and condition code register.
5. CPU scheduling information: A process needs to be scheduled for execution. Based on this
scheduling, it goes from ready to running. CPU Scheduling information contains process
priority (to determine which process goes first), pointers for scheduling queues (to mark the
order of execution), and various other scheduling parameters.
6. Accounting and business information: Contains details like CPU utilization, real-time used
by the process, number of jobs or processes, etc.
7. Memory-management information: Contains value of base and limit registers, details about
page and segment tables. It depends on the memory system of the OS in use.
8. I/O status information: Comprises I/O related information including list of I/O devices
allocated to the process, status, etc.

C)Process life cycle:


The process life cycle is the sequence of states that a process goes through during its
existence. The process life cycle can be divided into the following stages:
1. New: The process has been created but has not yet been scheduled for execution.
2. Ready: The process is ready to be executed.
3. Running: The process is currently being executed.
4. Waiting: The process is waiting for an event to occur, such as the completion of an I/O
operation.
5. Terminated: The process has finished executing.
In the new state, the process has been created but has not yet been allocated any resources.
The process is moved to the runnable state when it is scheduled for execution. The process is
moved to the running state when it is given the CPU. The process is moved to the blocked
state when it is waiting for an event to occur. The process is moved to the terminated state
when it has finished executing.

10) Consider the following five processes each having its own unique burst time and
arrival time.
Perform SJF Algorithm to find average waiting time and turn around time. (8 mark)
Process Arrival Burst
ID Time Time
P1 2 6
P2 5 2
P3 1 8
P4 0 3
P5 4 4

Non-Preemptive SJF:

Step 0) At time=0, P4 arrives and starts execution.


Step 1) At time= 1, Process P3 arrives. But, P4 still needs 2 execution units to complete. It
will continue execution.
Step 2) At time =2, process P1 arrives and is added to the waiting queue. P4 will continue
execution.
Step 3) At time = 3, process P4 will finish its execution. The burst time of P3 and P1 is
compared. Process P1 is executed because its burst time is less compared to P3.
Step 4) At time = 4, process P5 arrives and is added to the waiting queue. P1 will continue
execution.
Step 5) At time = 5, process P2 arrives and is added to the waiting queue. P1 will continue
execution.
Step 6) At time = 9, process P1 will finish its execution. The burst time of P3, P5, and P2 is
compared. Process P2 is executed because its burst time is the lowest.
Step 7) At time=10, P2 is executing and P3 and P5 are in the waiting queue.
Step 8) At time = 11, process P2 will finish its execution. The burst time of P3 and P5 is
compared. Process P5 is executed because its burst time is lower.
Step 9) At time = 15, process P5 will finish its execution.
Step 10) At time = 23, process P3 will finish its execution.

Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14

Average Waiting Time= 0+1+4+7+14/5 = 26/5 = 5.2

Turn Around time = (9-3) + (11-9) + (23-15) + (3-0) + (15-11) / 5


=6+2+8+3+4/5
= 23 / 5
= 4.6

You might also like