Quiz 2 Flashcards
Message Passing: Implementation of communication link (Physical vs Logical)
Physical: shared memory, hardware bus, network
Logical: direct or indirect, synchronous or asynchronous, automatic or explicit buffering
Message Passing: Direct Communcation
Processes MUST name each other explicitly: send or receive.
Properties of communication link:
- Links are established automatically
- Link is associated with exactly one pair of communicating processes.
- Between each pair there exists exactly one link.
- Link may be unidirectional, usually bi-directional.
Message Passing: Indirect Communication
Messages are directed & received from mailboxes (ports): each mailbox has a unique id, processes can only communicate if they share a mailbox.
Properties of communication link:
- Link established only if processes share a common mailbox.
- A link may be associated with many processes.
- Each pair of processes may share several links.
- Link may be unidirectional or bi-directional.
Indirect Communication operations
- Create a new mailbox (port)
- Send & receive messages through port
- Destroy a mailbox
Indirect Communication Issue: Who gets the message?
Problem: multiple processes want to receive a sent message, who gets it?
Solution:
1. Allow link to be associated with at most two processes.
2. Allow only one process at time to execute a receive operation.
3. Allow the system to select arbitrarily the receiver. Sender is notified who receiver is.
Synchronization
Blocking vs Non-blocking
Blocking is considered synchronous:
1. Blocking send- sender is blocked until the message is received
2. Blocking receive - receiver is blocked until a message is available
Non-blocking is considered asynchronous:
1. Non-blocking send- sender sends the message and continues.
2. Non-blocking receive- receiver receives a valid message or a null message.
If both send and receive are blocking, we have a rendezvous.
Buffering
Implemented in one of three ways
Queue of messages attached to the link.
- Zero capacity – no messages are queued on a link. Sender must wait for receiver (rendezvous)
- Bounded capacity – finite length of n messages. Sender must wait if link full
- Unbounded capacity – infinite length. Sender never waits
IPC Systems - POSIX
- Process first creates shared memory segment:
shm_fd = shm_open(name, O_CREAT | O_RDWR, 0666);
Also used to open an existing segment to share it - Set the size of the object
ftruncate(shm_fd, 4096); - Now the process could write to the shared memory
sprintf(shared memory, “Writing to shared memory”);
IPC Systems - Mach
Mach communication is message based:
A) Even system calls are messages
B) Each task gets two mailboxes at creation- Kernel and Notify
C) Only three system calls needed for message transfer
msg_send(), msg_receive(), msg_rpc()
D) Mailboxes needed for commuication, created via
port_allocate()
E) Send and receive are flexible, for example four options if mailbox full: Wait indefinitely Wait at most n milliseconds Return immediately Temporarily cache a message
IPC Systems - Windows
Message-passing centric via advanced local procedure call (LPC) facility:
A) Only works between processes on the same system
B) Uses ports (like mailboxes) to establish and maintain communication channels
C) Communication works as follows:
1. The client opens a handle to the subsystem’s connection port object.
2. The client sends a connection request.
3. The server creates two private communication ports and returns the handle to one of them to the client.
4. The client and server use the corresponding port handle to send messages or callbacks and to listen for replies.
Sockets
A socket is defined as an endpoint for communication
Concatenation of IP address and port – a number included at start of message packet to differentiate network services on a host
The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
Communication consists between a pair of sockets
All ports below 1024 are well known, used for standard services
ftp, http, …
Special IP address 127.0.0.1 (loopback) to refer to system on which process is running
3 Types of sockets
- Connection-oriented (TCP)
- Connectionless (UDP)
- MulticastSocket: class-data can be sent to multiple recipients
Remote Procedure Calls
A) Remote procedure call (RPC) abstracts procedure calls between processes on networked systems
Again uses ports for service differentiation
B) Stubs – client-side proxy for the actual procedure on the server
C) The client-side stub locates the server and marshalls the parameters
D) The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server
E) On Windows, stub code compile from specification written in Microsoft Interface Definition Language (MIDL)
F) Data representation handled via External Data Representation (XDL) format to account for different architectures
(Big-endian and little-endian)
G) Remote communication has more failure scenarios than local
Messages can be delivered exactly once rather than at most once
H) OS typically provides a rendezvous (or matchmaker) service to connect client and server
Pipes
A) Acts as a conduit allowing two processes to communicate
B) Implementation issues:
1. Is communication unidirectional or bidirectional?
2. In the case of two-way communication, is it half or full-duplex?
Half: data travel in one direction at any given time
Full: data travel in both direction at same time.
3. Must there exist a relationship (i.e., parent-child) between the communicating processes?
4. Can the pipes be used over a network?
Ordinary pipes – cannot be accessed from outside the process that created it. Typically, a parent process creates a pipe and uses it to communicate with a child process that it created.
Named pipes – can be accessed without a parent-child relationship.
Ordinary Pipes
UNIX treats them as files, thus can use read and write syscalls
Ordinary Pipes allow communication in standard producer-consumer style
Producer writes to one end (the write-end of the pipe)
Consumer reads from the other end (the read-end of the pipe)
Ordinary pipes are therefore unidirectional
Require parent-child relationship between communicating processes
Windows calls these anonymous pipes
Named Pipes
Named Pipes are more powerful than ordinary pipes
Communication is bidirectional
No parent-child relationship is necessary between the communicating processes
Several processes can use the named pipe for communication
Continue to exist after communicating processes have finished
Provided on both UNIX and Windows systems