P3L3. Inter-Process Communication Flashcards
What is inter-process communication (IPC)? What are some examples?
OS supported mechanisms for interaction among processes (coordination and communication)
- message passing IPC
- sockets, pipes, message queues
- memory-based IPC
- shared memory, memory mapped files
- higher-level semantics
- files, RPC
- synchronization
- primatives
How does message passing IPC work?
What is the kernel responsible for and how much user/kernel boudary crossings does this IPC require?
send/recv messages
OS creates and maintains a channel (e.g., buffer, FIFO queue)
OS provides interface to process - a port
- process send/write messages to a port
- process recv/read messages from a port
kernel required to:
- establish communication
- perform each IPC operation
- send: system call + data copy
- recv: system call + data copy
Request/Response:
4x user/kernel crossings + 4x data copies
What are the pros/cons of message passing IPC?
Pros:
+ simplicity. kernel does channel management and sychnronization
Cons:
- overhead. requires crossing user/kernel boundary for each message
How do pipes work? What form of IPC?
Carry byte stream between two processes (e.g., connect output from one process to input of another)
Pipes are an example of message passing IPC.
How do message queues work?
What is the OS responsible for?
What form of IPC?
Carry “messages” among processes
OS managment includes priorities, scheduling of message delivery
APIS: SysV and POSIX
Message queues are an example of message passing IPC.
How do sockets work?
What form of IPC?
- the sockets API supports send() and recv() operations that allow processes to send message buffers in and out of the kernel communication buffer.
- socket() creates a kernel-level socket buffer
- associate necessary kernel-level processing (TCP/IP)
> if different machines, channel is between processes and network device
> if same machone, bypass full protocol stack
Sockets are an example of message passing IPC.
How does shared memory IPC work?
What is the OS responsible for and how much user/kernel boudary crossings does this IPC require?
processes read and write to a shared memory region
OS establishes shared channel between the processes:
- physical pages mapped into virtual address space
- VA(P1) and VA(P2) map to the same physcial address
- VA(P1) != VA(P2)
- physical memory doesn’t need to be contiguous
What are the pros/cons of shared memory IPC?
Pros:
+ one shared memory segment is established the OS is out of the way
+ system calls only for setup
+ data calls potentially reduced (but not eliminated) for data to be visible to both processes it but be allocated from virtual memory addresses that belong to the shared region. if that’s not the case then data from the same address space has to be copied in and out of the shared memory region
Cons:
- explicit sychronization
- communication protocol, shared buffer management is the programmer’s responsibility
APIS: SysV, POSIX, memory mapped files
Copy (messages) vs Map (shared memory)
Copy
- CPU cycles to copy data to/from port
Map
- CPU cycles to map memory into address space
- CPU to copy data to channel
=> set up once, use many times = good payoff
=> can perform well for 1-time use (e.g., large data)