You are on page 1of 14

1

SAMRAT ASHOK TECHNOLOGICAL INSTITUTE


VIDISHA (M.P.)

OPERATING SYSTEM

CS-1745

ASSIGNMENT

GUIDED BY:- Submitted by:-


Proff. Vivek sharma Simran khan
Scholar no.-26128
En.no-0108cs161058
2

OPERATING SYSTEM
SUBJECT CODE :- CS-1745

MID SEM-I

Question-1) Define operating system? Do time sharing system differ from


multiprogramming ?If so how?
Answer -An operating system (OS), in its most general sense, is software that
allows a user to run other applications on a computing device. While it is possible
for a software application to interface directly with hardware, the vast majority of
applications are written for an OS, which allows them to take advantage of
common libraries and not worry about specific hardware details.
The operating system manages a computer's hardware resources, including:

 Input devices such as a keyboard and mouse


 Output devices such as display monitors, printers and scanners
 Network devices such as modems, routers and network connections
 Storage devices such as internal and external drives

Differences between multiprogramming and time sharing system-

Main difference between multiprogramming and time sharing is that


multiprogramming is the effective utilization of CPU time, by allowing several
programs to use the CPU at the same time but time sharing is the sharing of a
computing facility by several users that want to use the same facility at the
same time. Each user on a time sharing system gets her own terminal and gets
the feeling that she is using the CPU alone. Actually, time sharing systems use
the concept of multiprogramming to share the CPU time between multiple users
at the same time.
Question-2)Define process?What are the process states?also explain process
control block.
A process is defined as the smallest unit of work entity. Program which is in its
execution state is also called a processs.

Process control block (PCB) is a data structure which is associated with any
process and provides all the complete information about that process. The process
control block is "the manifestation of a process in an operating system". Process
3

control block is important in multiprogramming environment as it captures the


information pertaining to the number of processes running simultaneously.
Components of Process control block

The following are the various components that are associated with the process
control block PCB:

1. Process ID:
In computer system there are various process running simultaneously and each
process has its unique ID. This Id helps system in scheduling the processes. This Id
is provided by the process control block.
In other words, it is an identification number that uniquely identifies the processes
of computer system.

2. Process state:
As we know that the process state of any process can be New, running, waiting,
executing, blocked, suspended, terminated. For more details regarding process
states you can refer process management of an Operating System.
Process control block is used to define the process state of any process.
In other words, process control block refers the states of the processes.

3. Program counter:
Program counter is used to point to the address of the next instruction to be
executed in any process. This is also managed by the process control block.

4. Register Information:
This information is comprising with the various registers, such as index and stack
that are associated with the process. This information is also managed by the
process control block.

5. Scheduling information:
Scheduling information is used to set the priority of different processes. This is
very useful information which is set by the process control block. In computer
system there were many processes running simultaneously and each process have
its priority. The priority of primary feature of RAM is higher than other secondary
features. Scheduling information is very useful in managing any computer system.
4

6. Memory related information:


This section of the process control block comprises of page and segment tables. It
also stores the data contained in base and limit registers.

7. Accounting information:
This section of process control block stores the details relate to central processing
unit (CPU) utilization and execution time of a process.

8. Status information related to input / output:


This section of process control block stores the details pertaining to resource
utilization and file opened during the process execution.

The operating system maintains a table called process table, which stores the
process control blocks related to all the processes.

Question-3) Explain why spinlocks are not appropriate for single-processor


systems yet are often used in multiprocessor systems.

Answer- Spinlocks are not appropriate for single processor systems because the
condition that would break a process out of the spinlock can be obtained only by
executing a different process.If the process is not relinquishing the processor, other
process don’t get the opportunity to set the program condition required for the first
process to progress. In a multiprocessor system,other processes execute on other
processors and thereby modify the program state inorder to release the first process
from spinlock.
Question-5) Explain the various classical problems of synchronization?
Classical Problems of Synchronization-
In this tutorial we will discuss about various classic problem of synchronization.
Semaphore can be used in other synchronization problems besides Mutual
Exclusion.
Below are some of the classical problem depicting flaws of process
synchronaization in systems where cooperating processes are present.
We will discuss the following three problems:

1. Bounded Buffer (Producer-Consumer) Problem


2. The Readers Writers Problem
3. Dining Philosophers Problem
5

Bounded Buffer Problem-

 This problem is generalised in terms of the Producer Consumer problem,


where a finite buffer pool is used to exchange messages between producer and
consumer processes.
Because the buffer pool has a maximum size, this problem is often called
the Bounded buffer problem.

 Solution to this problem is, creating two counting semaphores "full" and
"empty" to keep track of the current number of full and empty buffers
respectively.
The Readers Writers Problem-

 In this problem there are some processes(called readers) that only read the
shared data, and never change it, and there are other processes(called writers)
who may change the data in addition to reading, or instead of reading it.
 There are various type of readers-writers problem, most centred on relative
priorities of readers and writers.
Dining Philosophers Problem-

 The dining philosopher's problem involves the allocation of limited resources to


a group of processes in a deadlock-free and starvation-free manner.
 There are five philosophers sitting around a table, in which there are five
chopsticks/forks kept beside them and a bowl of rice in the centre, When a
philosopher wants to eat, he uses two chopsticks - one from their left and one
from their right. When a philosopher wants to think, he keeps down both
chopsticks at their original place.

MID SEM-∏
SET- A
Question-1) What is CPU state? Explain how the notion of the CPU state is
useful in implementing multiprogramming?
Ans:- CPU state- It refers to the CPU modes or CPU scheduling modes. In this
state the process coming from ready state are executed by CPU. The scheduler
used here is short term scheduler which carries the process from ready state to
running state so CPU state can also be called as running state of process.
6

The CPU state helps in the concept of multiprogramming as the CPU can execute
many process with some time quantum in multitasking or one by one in
multiprogramming. The CPU can handle many process and hence helps in
multiprogramming.
Question-2) Out of Multiprogramming & Time sharing operating system
which one is having maximum CPU utilization & which one has maximum
user response and why? Can you categorize batch processing as the king of
multiprogramming?
Ans:-Multiprogramming is the allocation of more than one concurrent program on
a computer system and its resources. Multiprogramming allows using the CPU
effectively by allowing various users to use the CPU and I/O devices effectively.
Multiprogramming makes sure that the CPU always has something to execute, thus
increases the CPU utilization. On the other hand, Time sharing is the sharing of
computing resources among several users at the same time. Since this will allow a
large number of users to work in a single computer system at the same time, it
would lower the cost of providing computing capabilities. Hence allow maximum
user response.
Yes we can categorize the batch OS as the king operating system as when it is
added with multiprogramming facilities.
Question-3) What are the advantages of inter – process communication? How
communication takes place in shared memory environment? Explain
Ans:- Process to Process Communication: The unit of transfer in this layer is the
UDP datagram, and the destination is an input port within a host. Thus, the
destination of a message is specified as the pair.
Inter process communication messages mimic the reading and writing of files.
They are easier to use than pipes when more than
two process must communicate by using a single medium. Shared memory is the
fastest form of interprocess communication. The main advantage of shared
memory is that the copying of message data is eliminated. This allows a program
to handle many user requests at the same time.
Question-4) What are the necessary conditions for a deadlock?
Ans:- Deadlock Conditions are as follows:-

1. Mutual exclusion:- The resources involved must be unshareable ; otherwise,


the processes would not be prevented from using the resource when
necessary.
2. Hold and wait or partial allocation:- The processes must hold the resources
they have already been allocated while waiting for other (requested)
resources. If the process had to release its resources when a new resource or
7

resources were requested, deadlock could not occur because the process
would not prevent others from using resources that it controlled.
3. No pre-emption:- The processes must not have resources taken away while
that resource is being used. Otherwise, deadlock could not occur since the
operating system could simply take enough resources from running
processes to enable any process to finish.
4. Resource waiting or circular wait:- A circular chain of processes, with each
process holding resources which are currently being requested by the next
process in the chain, cannot exist. If it does, the cycle theorem (which states
that "a cycle in the resource graph is necessary for deadlock to occur")
indicated that deadlock could occur.
Question-5) What is process? Explain about various fields of Process Control
Block?
Ans:- Process:- A program under execution is called process. Or we can say that a
program in running state is called process.
The various fields of process control block are as under:-
1) Process state:- This tells us about different state of process. Like ready state,
running state, block state etc…
2) Process Id:- Every process has some unique Id. This field tell about the id
number of process.
3) Program counter:- This is a register which keeps the address of the next
instruction to be executed
4) Registers:- These are the temporary storage for different process in running
state.
5) Memory management :- These control the memory of the process.
Queastion-6) What is critical section problem? Give the condition that a
solution to the critical section problem must satisfy?
Ans:- In concurrent programming, concurrent accesses to shared resources can lead
to unexpected or erroneous behavior, so parts of the program where the shared
resource is accessed are protected. This protected section is the critical section or
critical region. It cannot be executed by more than one process.

1. Mutual exclusion :- If process is executing in its critical section, no other


process is executing in its critical section
2. Progress :- If no process is executing in its critical section and there exists
some processes that wish to enter their critical sections, then only those
processes that are not executing in their remainder section can participate in
the decision of which will enter its critical section next, and this decision
cannot be postponed indefinitely
8

o If no process is in critical section, can decide quickly who enters


o Only one process can enter the critical section so in practice, others
are put on the queue
o Bound waiting :- There must exist a bound on the number of times
that other processes are allowed to enter their critical sections after a
process has made a request to enter its critical section and before that
request is granted.

Question-7) What is mutual exclusion? How mutual exclusion can be


achieved. Explain?

Ans:- In computer science, mutual exclusion is a property of concurrency control,


which is instituted for the purpose of preventing race conditions; it is the
requirement that one thread of execution never enter its critical section at the same
time that another concurrent thread of execution enters its own critical section
Hardware solutions. On uniprocessor systems, the simplest solution to achieve
mutual exclusion is to disable interrupts during a process's critical section. ... Also,
if a process halts during its critical section, control will never be
returned to another process, effectively halting the entire system.
A way of making sure that if one process is using a shared modifiable data, the
other processes will be excluded from doing the same thing. while one process
executes the shared variable, all other processes desiring to do so at the same time
moment should be kept waiting; when that process has finished executing the
shared variable, one of the processes waiting; while that process has finished
executing the shared variable, one of the processes waiting to do so should be
allowed to proceed. In this fashion, each process executing the shared data
(variables) excludes all others from doing so simultaneously. This is called Mutual
Exclusion.

SET-B

Question-1) Is it possible to enjoy cent percent utilization of the main


memory?if so,how? What type of OS adopt for the technique?
Answer-
It is not possible to utilize cent percent of the main memory. There are operating
systems which can utilize memory to about 90% . The best operating system in the
context of memory utilization is multiprogramming system.
9

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.

Question-2) What is dining philosophers problem?discuss the solution to


dining philosopher’s problem using monitor?
Problem: Five philosophers live in a house, where a dining table has been laid for
them. The five philosophers have agreed to eat only spaghetti considering the fact
that it is the best for their lifestyle and health. All the philosophers require two
forks to eat. The table is arranged as shown below:
10

The eating arrangements are as follows: a round table as above where five plates of
spaghetti are kept for each philosopher and five forks.

 A philosopher who wishes to eat goes to his/her assigned place on the table
and eats the spaghetti plate in front of him using the two forks before him.
 The Aim of the Dinging philosopher’s problem is to allow all the
philosophers to eat.
 It must also satisfy the principles of mutual exclusion (no two philosophers
can use the same fork at the same time) while avoiding deadlock and
starvation.

Solution using monitors:

 A monitor is used to control access to state variables and condition variables.


 The fork and the spaghetti are not part of the monitor.
 Monitor procedures are defined for the actions of obtaining the forks and
putting them down.
 These are used as entry and exit segments for program segments (here
philosophers) which actually use the forks.
 The number of the philosophers is given by NUM_PHILO.
 A philosopher can be one of the three states THINKING, EATING,
HUNGRY.
 For each philosopher, there is going to be condition variables where the
philosopher will WAIT if he/she is hungry but one or both of the forks are
unavailable.
 If a philosopher wants to eat, he will check the state of his neighbours and
will eat of both his neighbours are not eating. Else he will wait.
 A philosopher who has finished eating will give his neighbour a chance to
eat, if they are hungry and their other chopstick is free
11

Question-3) Differentiate between virtual memory and back up memory?


discuss the benefits of virtual memory technique.
Answer-Virtual Memory- is a space where large programs can store themselves
in form of pages while their execution and only the required pages or portions of
processes are loaded into the main memory. This technique is useful as large
virtual memory is provided for user programs when a very small physical memory
is there.
In real scenarios, most processes never need all their pages at once, for following
reasons :

 Error handling code is not needed unless that specific error occurs, some of
which are quite rare.
 Arrays are often over-sized for worst-case scenarios, and only a small
fraction of the arrays are actually used in practice.
 Certain features of certain programs are rarely used.
Backup- or the process of backing up, refers to the copying
and archiving of computer data so it may be used to restore the original
after a data lossevent. Backups have two distinct purposes. The primary
purpose is to recover data after its loss, be it by data
deletion or corruption.The secondary purpose of backups is to recover
data from an earlier time, according to a user-defined data
retention policy, typically configured within a backup application for how
long copies of data are required. Though backups represent a simple form
of disaster recovery, and should be part of any disaster recovery plan,
backups by themselves should not be considered a complete disaster
recovery plan.

Question-4) what are the various security issues that arise in


multiprogramming and time shared system?
Answer- The various security issues that arise in multiprogramming and
time shared system?
Today, everyone depend their daily task mostly on computers. They do
research; accounting; programs; create, print, delete , and search files;
spend their leisure time through gaming and other activities that make
12

computers the major requirements to attain these. In this case, in a


multiprogramming and time-sharing environment where several users
share the system simultaneously, there will be no assurance that each
files, programs and data of each user will have the privacy or be restricted
to other users especially when the user does not know how to make his
files unexposed to other user. Two good examples of this situation are:
when using Team Viewer or the built-in Remote Desktop Service
(formerly Terminal Service). Both of them are used in the same way but
differ on how they will execute. For instance the Remote Desktop
Service, you can specify how many users can connect to your computer
and also you can specify their limitations. Then when the user is now
connected to your computer, he has the freedom on whatever he will do to
your computer, whether he will create, delete or search for files. And
worst, can copy and steal confidential information and data and transfer it
to his computer. It is an illegal transfer of electronic data. This is possible
because in a multiprogramming and time-sharing environment, you can
run programs at the same time while doing a specific task. In general
speaking, it is a multi-tasking activity.

Using system resources (CPU, memory, disk space, peripherals) with


improper accounting

When there are several users using the system simultaneously, it


cannot be guaranteed that there will be a specific amount of space or
limitations in using system resources. As the time goes by, each user
occupies a number of bytes of memory and disk space, and an amount of
programs process by the CPU and the amount of time that peripherals are
being use. And as the time increases, the system resources will
proportionally increase their capability and production. In this case, a
great possibility that there will be a shortage in memory and disk space
most especially when it is not use with proper accounting or allocation.
When this happens, all users sharing and connected to the system will
now be interrupted and worst it will make their programs crashed and
their paper works and the likes will not be save. But then there are
solutions to ease this scenario. A good example is through virtualization
which can make hosting of multiple virtualized environments within a
single OS instance possible (VMware software is an example).
13

Question-5) Define a thread? Give the benefits of multithreading. What


resources are used when a thread created?How do they differ from those used
when a process is created?
Answer- The smallest unit of work is called a process and a lightweight process is
called a thread. A thread is the smallest unit of processing that can be performed in
an OS. In most modern operating systems, a thread exists within a process - that is,
a single process may contain multiple threads.
Benefits of multithreaded programming can be broken down into four major
categories:

 Responsiveness. Multithreading an interactive application may allow a


program to continue running even if part of it is blocked or is performing a
lengthy operation, thereby increasing responsiveness to the user.
 Resource sharing. Processes may only share resources through techniques
such as shared memory or message passing. Such techniques must be
explicitly arranged by the programmer. However, threads share the memory
and the resources of the process to which they belong by default.
 Economy. Allocating memory and resources for process creation is costly.
Because threads share the resources of the process to which they belong, it is
more economical to create and context-switch threads. Empirically gauging
the difference in overhead can be difficult, but in general, it is much more
time consuming to create and manage processes than threads.
 Scalability. The benefits of multithreading can be greatly increased in a
multiprocessor architecture, where threads may be running in parallel on
different processors. A single-threaded process can only run on one
processor, regardless how many are available. Multithreading on a
multiCPU machine increases parallelism

The difference between the creation of thread and a process is a thread is smaller
than a process, thread creation typically uses fewer resources than process creation.
Creating a process requires allocating a process control block (PCB), a rather large
data structure.

Question-6. Is is possible to have a deadlock involving only a single process?


Explain.
Answer-
It is not possible to have a deadlock involving only one single process.
The deadlockinvolves a circular “hold-and-wait” condition between two or
14

more processes, so “one” process cannot hold a resource, yet be waiting for
another resource that it is holding.

Question-7) What is a semaphore?Explain its properties along with


drawbacks. Explain any problem and solve it by semaphore.
Answer-
A semaphore is a value in a designated place in operating system (or kernel)
storage that each process can check and then change. Depending on the value that
is found, the process can use the resource or will find that it is already in use and
must wait for some period before trying again. Semaphores can be binary (0 or 1)
or can have additional values. Typically, a process using semaphores checks the
value and then, if it using the resource, changes the value to reflect this so that
subsequent semaphore users will know to wait.
A semaphore S has the following properties:

 It always has a non-negative integer value (i.e., 0, 1, ...).


 It can be initialized to a non-negative integer value.
 A process can do a P operation (or "wait") on S, denoted P(S). P(S)
atomically decrements S by 1 only when S>0 holds; the process waits until
S>0 holds.
 A process can do a V operation (or "signal") on S, denoted V(S). V(S)
atomically increments S by 1.
 Starvation-freedom: If a process is at P(S), then it eventually completes
execution of the P(S) provided
o S>0 holds continuously after some point in time, or
o S>0 holds repeatedly (because V(S) is repeatedly done).

Following can be considered as the drawbacks of semaphores:


1. Queues. Semaphores are implemented with queues rather than busy wait
(as in spin locks)
2. Semaphores can result in priority inversion
3. Semaphores are usually more costly than mutexes