List the different inter process communication (IPC) mechanisms (with examples).
Question:
List the different inter process
communication (IPC) mechanisms (with examples).
Answer:
1. Shared Memory: Shared memory allows one or
more processes to communicate via memory that appears in all of their virtual
address spaces. Each process that wishes to share the memory must attach to
that virtual memory via a system call. The process can choose where in its
virtual address space the shared memory goes or it can let Linux choose a free
area large enough. When processes no longer wish to share the virtual memory,
they detach from it. So long as other processes are still using the memory the
detach only affects the current process. Its data structure is removed from the
shared memory data structure and de-allocated. The current process's page tables
are updated to invalidate the area of virtual memory that it used to share.
When the last process sharing the memory detaches from it, the pages of the
shared memory current in physical memory are freed.
2. Pipe: A pipe allows for data flow in one
direction; when bidirectional communication is needed, two pipes need to be
created.
Only related processes (those in the same
branch of the process tree) can communicate through a pipe.
The pipe is created by system call pipe():
Example: int pipe(int filedes[2]);
- creates a pair of file descriptors, pointing
to a pipe inode, and places them in the array pointed to by filedes. filedes[0]
is for reading, filedes[1] is for writing.
3. Message Queues: Differs from pipes in that
the caller need not (but can) read the messages in FIFO manner; it can select
the message it wants to acquire instead.
4. Signals: They are used to signal
asynchronous events to one or more processes. A signal could be generated by a
keyboard interrupt or an error condition such as the process attempting to
access a non-existent location in its virtual memory. Signals are also used by
the shells to signal job control commands to their child processes.
Example: signal(), kill(), alarm()
******************
Related Questions:
- List the different inter process communication (IPC) mechanisms with examples.
No comments:
Post a Comment