1 / 29

Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate wi

Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: We can synchronize the execution of the processes relative to each other. 2. Share important information. General IPC Commands.

charlot
Download Presentation

Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate wi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: We can synchronize the execution of the processes relative to each other. 2. Share important information.

  2. General IPC Commands IPCS – report inter-process communication facilities statusIPCRM – remove the specified message queues, semaphore sets and shared memory segmentsDifferent IPC Mechanisms In Unix:SEMAPHORESSHARED MEMORYPIPESMESSAGE QUEUES

  3. Semaphore Semaphore is a resource that contains a integer value. This integer value is stored in the kernel.  Semaphores are a mean of synchronizing processes by testing and setting.

  4. Semaphores enable multiple processes to perform mutual exclusion on critical section. Critical Section: Each process has a segment of code in which it changes common variable, writing to a file, updating table and so on…This section is called a critical section. Mutual Exclusion:  Only one process at a time may be in the critical section.

  5. Semaphores are used to avoid starvation and deadlock. Starvation:It occurs where a process is constantly denied access to resource it needs. Deadlock: It occurs when two or ore processes each hold a resource that the other need, and will not release the until each process obtains the desired resource. Its value is set to the number of resources it controls.For example, if we are sharing 3 printers then the semaphore value will be 3.

  6. Two types of operation can be carried out on semaphores: Wait Operation:If the semaphore value greater than zero, the resource is granted to the requesting process which decrements the semaphore value by the number of resources it acquired.If the semaphore value is zero or less, the requesting process decrements the semaphore value and blocks. Signal Operation:When a processes releases a shared resource, it increments the semaphore value by the number of resources it released.  The kernel notifies the queued process that the shared resource is now available and allows it to acquire the resource.

  7. Shared Memory  SM can be used in a uniprocessor as well as in multiprocessor. It can be used to communicate between different processes of the same user, different processes of the different user, and even between processes that runs at different times. It is also possible to broadcast data from one process to many others and collect data from many to onehence we can say that SM is a multidimensional communication media. SM allows multiple processes to share virtual memory space to exchange and change its content. This requires process synchronization to coordinate the access to the shared memory segment.

  8. The following are the steps involved in the client –server file copying program.Server gets access to a shared memory segment using a semaphore. The server reads from the input file into the shared memory segment. When the read is complete, the server again notifies the client using a semaphore. The client writes the data from the shared memory segment to the output file

  9. Unix Shared Memory System Calls UNIX provides the following system calls to perform the above action.Shmget- obtain a shared memory identifierShmat – attach to shared memorySmdat –detach from shared memoryShmcnl – shared memory control

  10. PIPES: Pipes provides a one-way flow of data. • A pipe is created by the pipe system call.Int pipe (int fd [2]);Here fd is an array of integers to store the file descriptor values of a pipe. A file descriptor is an integer that identifies the reading and writing end of the pipe. If the system call fails, it returns –1. if it is successful it returns to integer values fd[0] and fd[1].

  11. When using pipes kernel provides the synchronization between the reading and writing processes. when a process tries to write to a pipe that is full the calling process blocks until the pipe is able to receive more data. if a process attempts to read from an empty pipe, the calling process blocks until the pipe receives some data or the pipe closes. if a pipe is open for reading but not for writing then the calling process (the reading end) blocks.

  12. Data stored in the pipe is read on a First in First Out basis. The disadvantage with pipes is that they can only be used between processes that have a parent process in common. This is because a pipe is passed from one process to another by the fork system call.  There is no way for two totally unrelated processes to create a pipe between them and use it for IPC.

  13. Two processes communicate with each other using pipes in the following way.Before fork

  14. After Fork:

  15. First, process creates a pipe and then forks to create a copy of itself. • Next, the process closes the read end of the pipe and the child process closes the write end of the pipe. When the writing process finishes sending its data it should close its writing end to avoid blocking the reading process. By closing the writing end, an end-of-file (EOF) character will be put in the pipe. The (EOF) informs the reading process that there is no more data coming from the writing process, hence avoiding it to block.

  16. Message Queues:  It is like a pipe and is used to transfer messages between processes in Unix system.  A message queue is a queue onto which messages can be placed. A message is composed of message type and message data.

  17. First, process creates a pipe and then forks to create a copy of itself. Next, the process closes the read end of the pipe and the child process closes the write end of the pipe. When the writing process finishes sending its data it should close its writing end to avoid blocking the reading process. By closing the writing end, an end-of-file (EOF) character will be put in the pipe. The (EOF) informs the reading process that there is no more data coming from the writing process, hence avoiding it to block.

  18. Message Queues: It is like a pipe and is used to transfer messages between processes in Unix system. A message queue is a queue onto which messages can be placed. A message is composed of message type and message data.

  19. It can be either private or public. If it is private, it can be accessed only by its creating process or child processes of that creator. If it is public, it can be accessed by any process that knows the queue’s key. Message may be read by type, and hence there is no need to read them in a FIFO order, which is a case with the pipe.

  20. The msgget() system call is used to create a message queue. This system call accepts two parameters: 1)      A queue key2)      FlagsThe key may be one of: IPC_PRIVATE - used to create a private message queue Positive integer - used to create a publicly accessible message queue

  21. Mach IPC UNIX, provide communication between processes, and between hosts with fixed, global names (Internet addresses). There is no location independence of facilities, because any remote system needing to use a facility must know the name of the system providing that facility. Mach simplifies this picture by sending messages between location-independentPorts. The messages contain typed data for ease of interpretation

  22. IPC in MACH is done through • Ports • Messages.Almost everything in mach is an object and all objects are addressed via their communication ports.Messages are sent to this port to initiate the operation on the objects.When object is created, its creator also allocates a port to represent an object and obtains an access right to that port.Rights can be given out by the creator of the object and passed in the message.

  23. Ports  Ports are used to provide a one-way channel of communication for message passing.  A port has a single receiver and multiple senders.  Only one entity the kernel or user task can receive messages from a port, but anyone with permission may send to it.  A port is implemented as a protected, bounded queue within the kernel on which the object resides. They are not manipulated directly by the user.  To the kernel, a port is an object, which includes information about the port properties as well as internal data structures like locks, a message queue, and pointers to related objects.

  24. A port is referred by using a port name in the port name space. Every task has a port name space and it contains a list of port names. The port name space are also kernel protected means that a user can not simply add and remove entries in the port name space, he has to rely on the kernel to do it on request. If a queue is full, a sender may abort the send, wait for a slot to become available in the queue, or have the kernel deliver the message for it.

  25. Messages:A message is a collection of typed data. Available types are:·Pure-data (integers, floats, strings…)·Port rightsMemory regions

  26. Port Rights  It indicates to access a specific port.Three kinds of port rights:1) Receive Right:It allows task to receive the messages from this port. Only one receive right exists for a port.2) Send Right:It allows task to send the messages to this port. The number of send rights per port is not restricted.3) Send-one Right:It allows task to send one message to this port. The send-once right is destroyed after the message is sent.

  27. A message consists of a fixed-length header and a variable number of typed data objects. The header contains the destination’s port name, the name of the reply port to which return messages should be sent, and the length of the message. There are two types of messages in mach.1.Small messages2.Large messages The length of small messages is less than 128 bytes. Large messages carries one or two pages of out-of-line data. Small messages are used for most requests and replies. Large message are used for transferring data including file and device access and paging traffic.

More Related