4.1 Interprocess Communication

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Interprocess Communication

Shared Memory, Pipes and FIFO


Topics
• Shared Memory
• Pipes
• FIFO (Named Pipes)
Shared Memory
• Simplest & Fastest method for IPC
• Shared memory allows two or more processes to access the
same memory.
• When one process changes the memory, all the other processes
see the modification.
• Access to this shared memory is as fast as accessing a process’s
non-shared memory
• and it does not require a system call or entry to the kernel.
• It also avoids copying data unnecessarily.
• Because the kernel does not synchronize accesses to shared
memory, you must provide your own synchronization
Programing Assignment
Shared Memory

• Write three programs to use shared memory.


• Write
– One application to generate data and show
results.
– One to sum and print result
– One to multiply and print data.
Pipes
• A pipe is a communication device (serial) that
permits unidirectional communication.
• Data written to the “write end” of the pipe is
read back from the “read end.”
• used to communicate between two threads in
a single process or between parent and child
processes.
Pipes
• A pipe’s data capacity is limited.
• If the writer process writes faster than the reader
process consumes the data, and if the pipe
cannot store more data, the writer process blocks
until more capacity becomes available.
• If the reader tries to read but no data is available,
it blocks until data becomes available.
• Thus, the pipe automatically synchronizes the
two processes.
Programing Assignment
Pipes
– Implement programming examples given in
reading handout.
– Implement Circular Token Passing mechanism
using Pipes among threads or parent/child process
chain.
FIFO ( Names Pipes )
• A first-in, first-out (FIFO) file is a pipe that has
a name in the file system.
• Any process can open or close the FIFO.
• The processes on either end of the pipe need
not be related to each other.
• FIFOs are also called named pipes.
Programing Assignment
Named Pipes
– Implement programming examples given in
reading handout.
– Implement Circular Token Passing mechanism
using Pipes among 4 to 5 independent Processes.

You might also like