Labels

Showing posts with label Operating system. Show all posts
Showing posts with label Operating system. Show all posts

what is interprocess communication shared memory and message passing


Ø  Intercrosses communication –there are two type of intercrosses communication
1.       Independent process
2.     Cooperating process
1)          Independent process – A process is independent if it cannot affect or affected by the other process executing in the system and also this type of process does not share data will any other process.
2)        Cooperating process – a process is cooperating if it can affect or affected by other process executing in the system and also this type of process share data with other process.

v Cooperating process required an interprocess communication (IPC) technique that will allow them to exchange data and information.
v There are two fundamental of IPC –
·        Shared memory
·        Message passing
v Process cooperation is required for following reason  -
·        Information sharing - Information sharing several user maybe interested in the same piece of information (shared file).
·        Computation speedup- Computation speedup for task run faster we must break in into subtasks each of which will be executing in parallel with other.
·        Modularity –dividing the system function into separate process.
·        Convenience –an individual user may work on many tasks at the same time.
·        For EX. A user may be editing, listing to music and computing.

1)     Shared memory model –
·        A region of memory this is shared by cooperating process.
·        Process can them exchange information by reading and writing data to the shared reason.
·        Shared memory can be faster than message passing because message passing system are typically implemented using system call and require more time consuming task of kernel.
·        Ones shared memory is establish all access as routine work and no burden in kernel for sharing.
·        Shared memory reason reside in the address in the address space of the process creating the shared memory segment other process that wish to communicate must attach it to their address space.
·        Shared memory requires that two or more process agree for sharing memory.



                                                                       
                                          
            Shared memory
Example –
  • Producer consumer process this is a classic example, in which one process is producing data and another process is consuming the data. (In this example in the order in which it is produced, although that could vary.)
  • The data is passed via an intermediary buffer, which may be either unbounded or bounded. With a bounded buffer the producer may have to wait until there is space available in the buffer, but with an unbounded buffer the producer will never need to wait. The consumer may need to wait in either case until there is data available.
  • This example uses shared memory and a circular queue. Note in the code below that only the producer changes "in", and only the consumer changes "out", and that they can never be accessing the same array location at the same time.
  • First the following data is set up in the shared memory area:
#define BUFFER_SIZE 10
typedef struct {
     . . .
} item;
item buffer[ BUFFER_SIZE ];
int in = 0;
int out = 0;
  • Then the producer process. Note that the buffer is full when "in" is one less than "out" in a circular sense:
// Code from Figure 3.13
item nextProduced;
while( true ) {
/* Produce an item and store it in nextProduced */
nextProduced = makeNewItem( . . . );

/* Wait for space to become available */
while( ( ( in + 1 ) % BUFFER_SIZE ) == out )
      ; /* Do nothing */

/* And then store the item and repeat the loop. */
buffer[ in ] = nextProduced;
in = ( in + 1 ) % BUFFER_SIZE;
}
  • Then the consumer process. Note that the buffer is empty when "in" is equal to "out":
// Code from Figure 3.14
item nextConsumed;
while( true ) {
/* Wait for an item to become available */
while( in == out )
      ; /* Do nothing */
/* Get the next available item */
nextConsumed = buffer[ out ];
out = ( out + 1 ) % BUFFER_SIZE;

/* Consume the item in nextConsumed
     ( Do something with it ) */
}
2)    Message passing –
·        Message passing provide a technique to allow process to communicate and to synchronize their action without sharing the same address space.
·        In the message passing model communication takes place by mean of message exchanged between the cooperating processes.
·        It is useful in distributed environment where the communication process may reside on different computers connected by network.
·        For example, an internet chat program could be designed so that chat participates. Communicate with one another by exchanging message.
·        Message passing is useful for exchanging smaller amount of data.
·        Message passing is useful for exchanging smaller amount of data.
·        Message passing is slower than shared memory because it’s very time consuming task of kernel invention.
·        A message passing facility provides at least two operations send (message), receive (message).
·        If process p and q want to communicate, they must send message to and receive message from each other communication link must exist between them.
·        And it is a logical implementation, provided by several methods.
·        Direct or indirect communication.
·         Synchronous or asynchronous communication
·         Automatic or expict buffering.
·         For direct communication (naming) -
Send (P, message)-send a message to process P.
Receive (Q, message) – receive a message from process Q.
·        For direct communication (naming)
Send (A, message)-send a message mailbox A.
Receive (A, message)-receive a message mailbox.



            Message passing


operations on process in operating system


Ø Operations on process –
·        The process in most system can execute concurrently and they may be created and deleted dynamically.
·        So this system must provide a mechanism for process creation and termination.
1.       Process creation
2.      Process creation
1.         Process creation –
·        A process may create several new process creating process is called parent process and the new process are called the child process.
·        Each of this new process creates other process in form tree structure.
·        All operating system identity process according to a unique PID (process Identifier) number, which is integer number.
·        When a process create a new process, there are number of possibilities for execution exist –
                                                                    i.            The parent process continues to execute concurrently with its children.
                                                                 ii.            The process wait until some or all of its children have terminated
                                                               iii.            The process has new program loaded into it –
In UNIX operating system a new process created by the fork () system call.
exe() system call for execute created process.
Wait () system call for placed device queue or wait state.
In windows operating system new process created using createprocess() system call.
In this function there are two parameters passed - 
a.      STARUPINFO
b.     Process information

              

                               Process creation using the fork ( ) system call


2.     Process termination –
·        A process terminate when it finished its execution using exit () system call.
·        At this point the process may return a status value (integer values) to its parent process via wait() system call.
·        All the resources of process including physical and virtual memory open file and input – output buffers are deallocated by the operating system.
·        In window process terminated by terminateprocess() system call.
·        A parent may terminate the execution of one of its children for a several reason such as –
                                                                                  i.            The child has executed its uses of some of the resources that it has been allocated.
                                                                               ii.            The task assign to the child is no longer required.
                                                                             iii.            The parent is existing, and the operating system does not allow a child to continue if its parent terminates.
·        In such system, if a process terminates (either normally or abnormally) then all its children must be terminated is called cascading termination.
·        Terminate a process by using the exit() system call
·        When a process terminates its resources are deallocated by the operating system, but its entry in process table must remain there until the parent call wait(), but whose parent has not yet called wait() is known as zombie process.