Page 58 - DCAP103_Principle of operating system
P. 58

Unit 2: Process Management-I



            == out. The code for the producer and consumer processes follows. The producer process has   Notes
            a local variable nextproduced in which the new item to be produced is stored:

            while (1) {
            /* produce an item in nextproduced */
            while ( ( (in + 1) % BUFFER-SIZE) == out)
            ; /* do nothing */
            buffer [in] = nextproduced;
            in = (in + 1) % BUFFER-SIZE;
            1
            The consumer process has a local variable next consumed in which the item to be consumed
            is stored:

            while (I) {
            while (in == out)
            ; // do nothing
            nextconsumed = buffer [out] ;
            out = (out + 1) % BUFFER-SIZE;
            /* consume the item in nextconsumed */
            1

            2.5 Overview of Inter-Process Communication

            In the previous section, we showed how cooperating processes can communicate in a shared-memory
            environment. The scheme requires that these processes share a common buffer pool, and that the
            code for implementing the buffer be written explicitly by the application programmer. Another way
            to achieve the same effect is for the operating system to provide the means for cooperating processes
            to communicate with each other via an inter-process communication (PC) facility.

            IPC provides a mechanism to allow processes to communicate and to synchronize their actions
            without sharing the same address space. IPC is particularly useful in a distributed environment
            where the communicating processes may reside on different computers connected with a
            network. An example is a chat program used on the World Wide Web. IPC is best provided by
            a message-passing system, and message systems can be defined in many ways. In this section,
            we look at different issues when designing message-passing systems.

            2.5.1 Message-passing System
            The function of a message system is to allow processes to communicate with one another without
            the need to resort to shared data. We have already seen message passing used as a method of
            communication in Microkernels. In this scheme, services are provided as ordinary user processes.
            That is, the services operate outside of the kernel. Communication among the user processes
            is accomplished through  the passing of messages. An IPC facility provides at least the two
            operations— send(message) and receive(message). Messages sent by a process can be of either
            fixed or variable size. If only fixed-sized messages can be sent, the system-level implementation
            is straightforward. This restriction, however, makes the task of programming more difficult. On
            the other hand, variable-sized messages require a more complex system-level implementation,
            but the programming task becomes simpler. If processes P and Q want to communicate, they
            must send messages to and receive messages from each other; a communication link must exist
            between them. This link can be implemented in a variety of ways. We are concerned here not


                                             LOVELY PROFESSIONAL UNIVERSITY                                    51
   53   54   55   56   57   58   59   60   61   62   63