Interprocess Communications
An Introduction
|
Prof. David Bernstein
James Madison University
|
|
Computer Science Department
|
bernstdh@jmu.edu
|
Review
- Process:
- An instance of a program execution
- Associated with a Process:
- ID
- Memory containing text/instructions, initialized data,
unintialized data, stack and heap
- Arguments to
main()
- Environment
Motivation
- Independent Processes:
- Many processes are completely independent/unrelated
- A child process generally only starts as a copy of
its parent
- Processes Can Communicate through the File System:
- A child process has a copy of its parent's
file descriptors
- Different processes may open the same files
- We Often Also Want Processes To:
-
Coordinate
their actions
- Exchange information other than through the file system
Signals
- Purpose:
- Use:
- Notify a process that an event has occurred
- A Hardware Analogy:
Data Transfer Mechanisms
- What Happens:
- Processes transfer data through the kernel space
- How They Works
- One process transfers data from user memory to kernel memory
(usually referred to as a write)
- One process transfers data from kernel memory to user
memory (usually referred to as a read)
Types of Data Transfer Mechanisms
- Byte Stream:
- The exchange involves an undelimited byte stream as with
files
(hence one process writes an arbitrary number of bytes and the
other reads an arbitrary number of bytes)
- Examples include pipes, FIFOs (aka named-pipes), and
stream sockets
- Message Oriented:
- The exchange involves coherent messages that can't be
decomposed (hence one process writes a whole message and the
other reads a whole message)
- Examples include message queues and datagram sockets
Other Characteristics of Data Transfer Mechanisms (cont.)
- Destructive:
- In some cases, a read operation "consumes" the data
(i.e., the data become unavailable to other
readers)
- Blocking:
- In some cases, the reader blocks if the data are not
available
Shared Memory Mechanisms
- What Happens:
- Multiple processes share memory
- How It Works:
- The kernel makes page-table entries in each process point
to the same pages of memory
Shared Memory Mechanisms (cont.)
- Properties:
- Fast
- Require synchronization to avoid conflicts
- Non-destructive (i.e., data in shared memory is visible to all
processes that share it)
- Examples:
- Shared memory, memory mappings (including anonymous mappings
and mapped files)
Synchronization Mechanisms
- Purpose:
- Allow processes to coordinate their actions
- Kinds of Uses:
- Coordinate other kinds of information exchange
(e.g., updating shared memory, updating a file)
- Coordinate steps in an algorithm
Synchronization Mechanisms (cont.)
- Semaphores:
- A non-negative integer that is maintained by the kernel
that can be used in a vareity of different ways
- File Locks:
- Read locks can be shared; write locks are exclusive (i.e.,
only one process can hold a write lock on a file/region)
Accessibility of IPC Mechanisms
- The Question:
- What permission/access scheme is used to govern
which processes have access to the entity used by the IPC
mechanism?
- Schemes:
- Related processes only
- Permission masks
- Other
Persistence of IPC Mechanisms
- The Question:
- What is the lifetime of the entity used by the IPC
mechanism?
- Lifetimes:
- Process Persistence - the entity remains in existence only
as long as it is held open by at least one process
- Kernel Persistence - the entity exists until it is
explicitly deleted or the system is shut down
- File System Persistence - the entity exists until it is
explicitly deleted (even if the system is shut down and
restarted)
Properties of IPC Mechanisms
There's Always More to Learn