Inter Process Communication (IPC) and its facility provided in UNIX

Programming Paradigm

Interprocess Communication (IPC)

Inter process communication may be a mechanism which allows processes to  communicate one another  and synchronized. There are two ways of procceses communication.

1. Shared memory

2.Message passing

Both of methods are often implemented by operating system.

 

Inter Process Communication

 

1. Shared memory:

Shared memory may be a memory allocation between two or more processes. Within the shared memory model, a neghibourhood of memory that’s shared  by cooperating processes is established. Processes can then exchange information by reading and writing data to the shared region. with in the message-passing model, communication takes place by means of messages exchanged between the cooperating processes.

 

2. Message passing:

In this method processes  don’t use any of shared memory for communication. if two processes p1 and p2 want to communicate, they proceed as follow:

  • Establish a communication link
  • Exchange messages by using premitives

We need two primitives

send(message, destination) or send(message)
receive(message, host) or receive(message)

 

Message passing provides a mechanism to permit processes to communicate and to synchronize their actions without sharing an equivalent address space. It’s particularly useful during a distributed environment, where the communicating processes may reside on different computers connected by a network. For instance , an online chat program might be designed in order that chat participants communicate with each other by exchanging messages.

Messages sent by a process are often either fixed or variable in size. If only fixed-sized messages are often sent, the system-level implementation is simple.

A message have two parts:

  • Header
  • Body

The header part used for storing  message type, destination id, source id, message length and control information.

 

Examples of IPC system are:

  • POSIX Shared Memory
  • Mach
  • Windows
  • UNIX

Why  IPC needed?

Inter process communication is required because:

  • speedup modularity
  • Computational
  • Privilege separation
  • It helps operating system to communicate each other
  • Simplicity (the simplicity comes out of parallelism of the system)
  • If we’d like to send/receive data between two or more processes you can’t ask each others variables or You would like another way to read /write to some “shared” area, or call some shared “function”. IPC was designed with some kind of standards once you want to figure with quite one process.
  • You have 2 processes , each running an executable which suggests each references all its variables with an equivalent names, but each variable is exclusive to every process.
  • There is no sharing. so if you would like to communicate 2 processes you used ipc.

 

 

UNIX IPC:

IPC is played a important role in Unix-variant operating system.

PIPES:

Pipes are an easy synchronized way for information passing between two process. Pipe uses a FIFO scheme to getting data and it also can be viewed as a special file that store a limited data. Data is written to at least one end and read from another end. The processes on the ends  have  no easy way to identify what process is on the other end of the pipe.

Most unix limit pipes to 5120K. the supervisor call instruction wait() is used to add data to pipe. write() takes a file descriptor , a buffer, the size of the buffer as a parameter. Read() function is used to get data from a pipe. It will block the data  if there is no data to be read.

The pipe() command is used to create unnamed pipes in UNIX. This call returns 2 pipes. Both pipes support bidirectional communication. In a full duplex environment, each process reads from one pipe and writes from another pipe. While in a half duplex , the one file descriptor is used for reading and the second for writing.

 

For sending of output of one  process to another  process as input pipes are commonly used in UNIX.

There are several steps to Using unnamed pipes in a UNIX environment:

  • Create the pipes needed
  • Child process generated
  • For the association of ends of pipes used the close/duplicate file descriptors
  • Close the unused ends of pipes
  • Perfom the communication
  • The remaining file descriptors will closed
  • Wait for the termination of child process

 

To simplify, UNIX provides two system calls. After accepting a shell command to be executed as input the call popen() returns a pointer  to a file. The popen() call automatically generates a child process,  which exec() a shell and runs the indicated to the file. This command either have read or write access to the file depends on the falg passed in. To close the data stream opened with popen(), the pclose() call is used.

 

By using mknod the named pipes can be created on UNIX system. The mknod system call,  useable only by the superuser , takes a path, access permissions and a device as parameters and creates a pipe referred to by the user-specified path.

 

The additional call mkfifo() will be provided that can be used by all users  but this is only capable of FIFO pipes.

 

 

For more help related to Operating Systems visit: Operating Systems

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *