Vous êtes sur la page 1sur 5

Q1. What are the cooperating processes and how they communicate?

Explain
by taking a suitable example.

Ans. A process is independent if it cannot affect other other process or be affected by it.
Any process that does not share data with others is independent. Otherwise the process
is cooperating. Cooperation is done to provide information sharing, computational
speedups, modularity and convenience. To allow cooperation there should be some
mechanism for communication (called IPC: Inter-Process Comm.) and to synchronize
their actions.

The best way to see the cooperation is by seeing an example of consumer-producer.


Producer produces and consumer consumes. Producer puts its production in a buffer
and consumer picks it from the buffer. (Buffer could be provided by OS using IPC).

Reasons for needing cooperating processes

(a) Modularity – Modularity involves dividing complicated tasks into smaller subtasks.
These subtasks can completed by different cooperating processes. This leads to faster
and more efficient completion of the required tasks.
(b) Information Sharing – Sharing of information between multiple processes can be
accomplished using cooperating processes. This may include access to the same files.
A mechanism is required so that the processes can access the files in parallel to each
other.
(c) Convenience – There are many tasks that a user needs to do such as compiling,
printing, editing etc. It is convenient if these tasks can be managed by cooperating
processes.
(d) Computation Speedup – Subtasks of a single task can be performed parallely
using cooperating processes. This increases the computation speedup as the task can
be executed faster. However, this is only possible if the system has multiple processing
elements.

Inter-process communication (IPC) allows the running of programs concurrently in


an operating system. There are quite a number of methods used in inter-process
ommunications. They are:
(a) Pipes: A pipe is a unidirectional data connection between two processes. A
process uses file descriptors to read from or write to a pipe. A pipe is designed as a
queue offering buffered communication. Therefore the operating system will receive
messages written to the pipe and make them available to entities reading from the pipe.
(b) Named Pipes: This is a pipe with a specific name. It can be used in processes that
do not have a shared common process origin. Example: This FIFO where the data is
written to a pipe is first named.
(c) Message Queuing: This allows messages to be passed between messages using
either a single queue or several message queues. This is managed by the system
kernel. These messages are coordinated using an Application Program Interface
(API).
(d) Semaphores: This is used in solving problems associated with synchronisation and
avoiding race conditions. They are integer’s values which are greater than or equal to
zero.
(e) Shared Memory: This allows the interchange of data through a defined area
of memory. Semaphore value has to be obtained before data can get access to
shared memory.

For example, the Unix pipe creates an example of cooperation

cat my_header.h | sed 's/STDOUT/stdout/g' > my_header.h

Here the process, cat produces data by writing-out the file my_header.h which is piped
to the sed which edits the data. The is an example of mutual cooperation, and uses a
shared resource to communicate data: the pipe.

------------------------------------------------------------------

Q2. What are the characteristics of a good scheduling algorithm? Give a


comparison of FCFS and RR algorithm giving pros and cons of each with
example.

Ans2. The scheduling program which is a system software concerned with scheduling
is called the scheduler and the algorithm it uses is called the scheduling algorithm.

Various criteria or characteristics that help in designing a good scheduling algorithm


are:

(a) CPU Utilization − A scheduling algorithm should be designed so that CPU remains
busy as possible. It should make efficient use of CPU.

(b) Throughput − Throughput is the amount of work completed in a unit of time. In


other words throughput is the processes executed to number of jobs completed in a unit
of time. The scheduling algorithm must look to maximize the number of jobs processed
per time unit.

(c) Response time − Response time is the time taken to start responding to the
request. A scheduler must aim to minimize response time for interactive users.

(d) Turnaround time − Turnaround time refers to the time between the moment of
submission of a job/ process and the time of its completion. Thus how long it takes to
execute a process is also an important factor.

(e) Waiting time − It is the time a job waits for resource allocation when several jobs
are competing in multiprogramming system. The aim is to minimize the waiting time.

(f) Fairness − A good scheduler should make sure that each process gets its fair share
of the CPU.

Comparison of FCFS and RR algorithm


(a) First Come First Serve (FCFS)
Advantages:
(i) FCFS algorithm doesn't include any complex logic, it just puts the process requests in
a queue and executes it one by one.
(ii) Hence, FCFS is pretty simple and easy to implement.
(iii) Eventually, every process will get a chance to run, so starvation doesn't occur.
Disadvantages:
(i) There is no option for pre-emption of a process. If a process is started, then CPU
executes the process until it ends.
(ii) Because there is no pre-emption, if a process executes for a long time, the
processes in the back of the queue will have to wait for a long time before they get a
chance to be executed.
(b) Round Robin (RR)
Advantages:
(i) Each process is served by the CPU for a fixed time quantum, so all processes are
given the same priority.
(ii) Starvation doesn't occur because for each round robin cycle, every process is given
a fixed time to execute. No process is left behind.
Disadvantages:
(i) The throughput in RR largely depends on the choice of the length of the time
quantum. If time quantum is longer than needed, it tends to exhibit the same behavior
as FCFS.
(ii) If time quantum is shorter than needed, the number of times that CPU switches from
one process to another process, increases. This leads to decrease in CPU efficiency.

Usage of FCFS and RR in Different Situations

Situation 1: The incoming processes are short and there is no need for the processes
to execute in a specific order.

In this case, FCFS works best when compared to RR because the processes are short
which means that no process will wait for a longer time. When each process is executed
one by one, every process will be executed eventually.

Situation 2: The processes are a mix of long and short processes and the task will only
be completed if all the processes are executed successfully in a given time.

RR scheduling works efficiently here because it does not cause starvation and also
gives equal time quantum for each process.

Q3. What is the need for Page Replacement? Discuss different page
replacement techniques giving a performance comparison.

Ans3. In an operating system that uses paging for memory management, a page
replacement algorithm is needed to decide which page needs to be replaced when new
page comes in.
Page Fault – A page fault happens when a running program accesses a memory page
that is mapped into the virtual address space, but not loaded in physical memory.
Since actual physical memory is much smaller than virtual memory, page faults happen.
In case of page fault, Operating System might have to replace one of the existing pages
with newly needed page. Different page replacement algorithms suggest different ways
to decide which page to replace. The target for all algorithms is to reduce number of
page faults.
Page Replacement Algorithms :
(a) First In First Out (FIFO) – This is the simplest page replacement algorithm. In this
algorithm, operating system keeps track of all pages in the memory in a queue, oldest
page is in the front of the queue. When a page needs to be replaced page in the front of
the queue is selected for removal.

For example-1, consider page reference string 1, 3, 0, 3, 5, 6 and 3 page slots.


Initially all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots
—> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest page slot i.e
1. —>1 Page Fault.
Finally 6 comes, it is also not available in memory so it replaces the oldest page slot i.e
3 —>1 Page Fault.

Belady’s anomaly – Belady’s anomaly proves that it is possible to have more page
faults when increasing the number of page frames while using the First in First Out
(FIFO) page replacement algorithm. For example, if we consider reference string 3, 2,
1, 0, 3, 2, 4, 3, 2, 1, 0, 4 and 3 slots, we get 9 total page faults, but if we increase slots
to 4, we get 10 page faults.
(b) Optimal Page replacement – In this algorithm, pages are replaced which would not
be used for the longest duration of time in the future.
For eg; Let us consider page reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 and 4 page slots.
Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already there so —> 0 Page fault.
when 3 came it will take the place of 7 because it is not used for the longest duration of
time in the future.—>1 Page fault.
0 is already there so —> 0 Page fault..
4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.
Optimal page replacement is perfect, but not possible in practice as operating system
cannot know future requests. The use of Optimal Page replacement is to set up a
benchmark so that other replacement algorithms can be analyzed against it.

(c) Least Recently Used – In this algorithm page will be replaced which is least
recently used.
For eg; Let say the page reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 . Initially we have 4
page slots empty.
Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already their so —> 0 Page fault.
when 3 came it will take the place of 7 because it is least recently used —>1 Page fault
0 is already in memory so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.

Q4. What is the requirement of Memory Management? How the address binding
of instructions and data is carried to memory address.
Q5. What is the purpose of directory structure in file system? Explain various
types of directory structure with suitable diagram

Vous aimerez peut-être aussi