COOPERATING PROCESS IN OS

  COOPERATING PROCESS:

The processes executing in a system may be either independent or co-operating process.

Independent process:

·         A process is independent if it cannot affect other process or be affected by it.
·         Any process that does not share data with others is independent

Cooperating process:

·         If it can affect Or affected by the other processes executing in the system
·         Shares data with other processes
·         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.

Advantages of cooperating process:

·         Information sharing-Several users may which to share the same information e.g. a shared file. The O/S needs to provide a way of allowing concurrent access.
·         Computational speedup-Some problems can be solved quicker by sub-dividing it into smaller tasks that can be executed in parallel on several processors.
·         Modularity-The solution of a problem is structured into parts with well-defined interfaces, and where the parts run in parallel.
·         Convenience-A user may be running multiple processes to achieve a single goal, or where a utility may invoke multiple components, which interconnect via a pipe structure that attaches the stdout of one stage to stdin of the next etc.

Example:

Below is a very simple example of two cooperating processes. The problem is called the Producer Consumer problem and it uses two processes, the producer and the consumer.

Producer Process: It produces information that will be consumed by the consumer.


Consumer Process: It consumes information produced by the producer.
Both processes run concurrently. If the consumer has nothing to consume, it waits.

There are two versions of the producer. In version one, the producer can produce an infinite amount of items. This is called the Unbounded Buffer Producer 
Consumer Problem.
In the other version, there is a fixed limit to the buffer size. 
When the buffer is full, the producer must wait until there is some space in the buffer before it can produce a new item.
To allow producer and consumer processes to run concurrently, we must have available a
buffer of items that can be filled by the producer and emptied by the consumer.
 A producer can produce one item while the consumer is consuming another item. 
The producer and consumer must be synchronised, so that the consumer does not try to consume an item that has not yet been produced. 
In this situation, the consumer must wait until an item is produced.
The unbounded-buffer producer i.e. the consumer problem places no practical limit on the
size of the buffer.
The consumer may have to wait for new items, but the producer can always produce new
items.
 The bounded-buffer producer consumer problem assumes that there is a fixed buffer
size. 
In this case, the consumer must wait if the buffer is empty and the producer must wait if
the buffer is full.
The buffer may be either provided by the operating system through the use of IPC (Inter
Process Communication), or explicitly coded by the application programmer with the use of
shared memory.

Example:

A print program  produces characters that are consumed by the printer driver. A compiler may produce
assembly code, which is consumed by an assembler. The assembler, in turn, may produce
object modules, which are consumed by the loader.


No comments:

Post a Comment