Home » Operating Systems

Cooperating processes in the Operating System

In this article, we will learn about the introduction of cooperating processes, and try to understand the reasons for which the processes allow the cooperation in the operating system.
Submitted by Prerana Jain, on August 13, 2018

Cooperating processes

In the computer system, there are many processes which may be either independent processes or cooperating processes that run in the operating system. A process is said to be independent when it cannot affect or be affected by any other processes that are running the system. It is clear that any process which does not share any data (temporary or persistent) with any another process then the process independent. On the other hand, a cooperating process is one which can affect or affected by any another process that is running on the computer. the cooperating process is one which shares data with another process.

There are several reasons for providing an environment that allows process cooperation:

  • Information sharing
    In the information sharing at the same time, many users may want the same piece of information(for instance, a shared file) and we try to provide that environment in which the users are allowed to concurrent access to these types of resources.
  • Computation speedup
    When we want a task that our process run faster so we break it into a subtask, and each subtask will be executing in parallel with another one. It is noticed that the speedup can be achieved only if the computer has multiple processing elements (such as CPUs or I/O channels).
  • Modularity
    In the modularity, we are trying to construct the system in such a modular fashion, in which the system dividing its functions into separate processes.
  • Convenience
    An individual user may have many tasks to perform at the same time and the user is able to do his work like editing, printing and compiling.

A cooperating process is one that can affect or be affected by other process executing in the system cooperating process an:

  1. Directly share a logical address data space (i.e. code & data) - This may result in data inconsistency. It is implemented on threads.
  2. Share data only through files/ messages - So we will deal with various to order....orderly execution of cooperating process so that data consistency is maintained.

Example- producer-consumer problem

There is a producer and a consumer, producer produces on the item and places it into buffer whereas consumer consumes that item. For 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 objects modules which are consumed by the loader.


Producer process

    while(true)
    {  
        produce an item &
        while(counter = = buffer-size);
        buffer[int] = next produced;
        in = (in+1) % buffer- size;
        counter ++;
    }

Consumer process

    While(true)
    { 
        while (counter = = 0);
        next consumed = buffer[out];
        out= (out+1) % buffer size;
        counter--;
    }

Here,

  • in variable is used by producer t identify the next empty slot in the buffer.
  • out variable is used by the consumer to identify where it has to the consumer the item.
  • counter is used by producer and consumer to identify the number of filled slots in the buffer.

Shared Resources

  1. buffer
  2. counter

When producer and consumer are not executed can current then inconsistency arises. Here the value of a counter that is used by both producer and consumer will be wrong if both are executed concurrently without any control. The producer and consumer processes share the following variables:

    var n;
    type item = .....;
    var Buffer : array [0,n-1] of item;
    In, out:0..n-1;

With the variables in and out initialized to the value 0. In The shared buffer there are two logical pointers; in and out that is implemented in the form of a circular array. The in variables points to the next free position in the buffer and out variable points to the first full position in the buffer. When, in = out the buffer is empty and when in+1 mod n = out the buffer is full.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.