Please enable JavaScript.
Coggle requires JavaScript to display documents.
Inter-Process Communication (IPC) (Shared memory (OS requirements (OS…
Inter-Process Communication
(IPC)
Basic IPC characterisics
Content
Fixed
Variable
Size
Fixed
Variable
Data transfer
Datagram
Messages are individually addressed, sent, and delivered
Stream
Destination is established, and then messages sent and received sequentially to the destination
Blocking/nonblocking
Blocking
Returns after message enters the system
Nonblocking
Returns immediately but work to deliver message may still be pending
Synchronous/Asynchronous
Synchronous
Call returns after message received
Asynchronous
May return before message received
Uses
Signals
Process to kernel
"System calls"
Kernel to process
"Signals"
When do signals occur?
Sent by kernel when...
Process execution causes an exception
Process runs out of resources
Process loses connection
Process needs to be notified of special event
Sent by another process when...
Sending a signal from one process to another
User specific signals
Killing a process
Implementation: signal table
Each process has a signal table
One entry for each signal
Entries define what to do when signal occurs
Default action
Exit
Core
Ignore
Handle signal
Problem:
action is part of the application space, but how does the kernel get the application code to run?
Target of signal may be executing at any location
Target of signal could be blocked in a system call
Soltuions
Waiting thread
Thread within process is designated to wait for signals
Thread uses sigwait() call to indicate wait for signals
sigwait() blocks until a signal of interest fires
Kernel returns address of user specified handler to be run
Thread runs the handler (service the signal)
Thread returns to waiting for a new signal when handler completes
Single-threaded Process
Suspend all processes to process the signal
Issues
When handler code completes, execution must pick up where it left off
The code to run is specified in the signal table
Solution: signal trampoline
Calls the user-specified handler code
Calls sigdone() as its last action
sigdone() sets stack pointer so a context switch back to the target will pick up the old context
When processing a signal, the kernel blocks from that signal going off again
"A very limited form of IPC"
Send/Receive
(datagrams)
Send
Application calls send()
2a. If a receiver is waiting
Message copied into receiver's buffer
Receiving process is placed in a ready queue
send() system call returns immediately
2b. Else, receiver is not waiting
Process will block until...
3a. A receiver arrives
or
3b. The sender is killed
or
3c. System determines no receiver will ever arrive
Receive
Application calls receive()
2b. Else, sender is not waiting
Receiver process waits until...
3a. A send() is made to it
or
3b. The receiver is killed
or
3c. System determines a message will never arrive
2a. If sender is waiting
Message copied from sender into buffer
Sender put onto ready queue
receive() system call returns
Send/Receive variants
S/R/ReceiveAny
Application calls receiveAny()
Caller checks if any process waiting to send to it, and accepts messages on a FIFO basis
Use a blocked queue for each process, having senders block on the queue of the process they are sending to
S/R/Reply
Sender remains blocked until the receiver has replied
Sender supplies two buffers:
Buffer to send from
Buffer to receive into
Indirect communication
Motivation
S/R IPC requires knowing the ID of the process being communicated with
Communication is often indirect
S/R IPC requires special functions for indirect communication
Ports and mailboxes
Ports/mailboxes are named so other processes can easily identify them
Instantiated by a process
Receiving from a port
If a port has a message
Message copied to receive buffer
Put receiver on ready queue
Receive() returns immediately
Else, port does not have a message
Receiver is blocked and added to a queue or processes waiting on that port
Sending to a port
If a receiver is waiting
Copy message to receiver
Receiver is put on a ready queue
Send() returns immediately
Else, no receiver is waiting
Block on port
Streams
What is
Connection opened between sending/receiving process
Address is via a descriptor returned from opening connection
Data is buffered between sender/receiver
Communication guaranteed in-order
Error-corrected
Pipes
OS creates a circular buffer in memory
write() writes to the and wakes up the reading process if necessary
read() reads from the buffer and wakes up the writing process if necessary
If buffer is empty, reading process blocks
Shared memory
A segment of memory shared by multiple processes
Each process can read from and write to the memory
OS does not impose restrictions on read/write or guarantee atomic updating of the memory
Occupies some address space within each process's memory
Named vs. Unnamed
Named shared memory
Shared memory region has a name associated with it
Name can be passed from process to process
Name can be determined independently
Can be attached to by any process with the correct permissions
Is persistent but not durable
(Can exist with no process referencing it, but disappears when the system restarts)
Unnamed shared memory
Only child processes inherit shared segments from parent
Cannot be used by two unrelated processes
Shared memory is persistent
Simple to implement but inflexible
Easy to manage
OS requirements
OS must keep track of named segments
Must be able to check permissions
Must have policies about shared memory usage
Location
Fixed
Good
because processes can share pointers
Bad
because finding a common free space between all of the processes is really hard
Variable
Good
because you don't have to find a common free space
Bad
because manipulating data structures is more expensive
Benefits vs. Problems
Benefits
Efficient
: no per-usage cost, just single startup cost
Familiarity
: easy to understand semmantics
Data-independent
: independent of data size
Non-blocking
: processes to not need to block during IPC
Problems
Processes can interfere destructively
Processes must use their own synchronization primitives or use kernel synchronization primitives
Resources may be wasted during busy-waits
Process code is highly interdependent
Logical vs. Physical Address
Logical address
Generated and used by code
Seen in code
Belongs to processes contiguous address space
Translated by MMU to physical address
Physical address
Generated by the MMU
Refers to physical memory
Sent down bus by MMU to read/write memory
Not visible to the process