Interprocess Communicatio N
Interprocess Communicatio N
Communicatio
n
OUTLINE
⚫Introduction
⚫APIs for Internet Protocols
Message passing
takes several forms
such as: pipes,
FIFO, Shared
Memory, and
Message Queues.
IPC - Introduction
• The method of IPC used may vary based on the bandwidth
and latency of communication between the threads, data
type
• Distributed computing systems make use of these
facilities/resources to provide application programming
interface (API) which allows IPC to be programmed at a
higher level of abstraction. (e.g., send and receive)
Main IPC Methods
Method Provided by (Operating systems or other environments)
All POSIX systems, Windows. This technique may carry race condition
memory-mapped file
risk if a temporary file is used.
Introduction
Shared Memory
In a Non-Distributed
System:
Two approaches to
communication:
⚫ Shared memory
◦ Information placed in a
common memory area Message Passing
⚫ Message passing
◦ Generally makes use of
IPC mechanisms made
available by the
underlying OS
◦ Ex : Pipes, Sockets
Introduction
Communication In a Distributed System
⚫ Message Passing
⚫ Only mechanism available for the passing of messages is
network communication
◦ Message passing involves the sending process creating
and enqueuing a message to be delivered to the
receiving process.
◦ The receiving process then dequeues and handles the
message accordingly.
⚫ Send() and receive() operations
This activity involves the communication of data from the sending process to the
receiving process and may involve the synchronization of the two processes.
Characteristics of IPC
Since Berkeley sockets were largely the first socket implementation and
most programmers are familiar with them, a large number of systems use
Berkeley sockets as their primary network API
Sockets
A non-exhaustive list includes:
•FreeBSD, NetBSD, OpenBSD
•Linux based systems
•Microsoft Windows sockets "Winsock"
•Java Sockets follow the same model, with java.net.Socket
•Python sockets
•Perl sockets
•Most other networked operating systems
Berkeley Sockets API Functions
• socket() creates a new socket of a certain socket type, identified by an integer
number, and allocates system resources to it.
• bind() is typically used on the server side, and associates a socket with a socket
address structure, i.e. a specified local port number and IP address.
• listen() is used on the server side, and causes a bound TCP socket to enter
listening state.
• connect() is used on the client side, and assigns a free local port number to a
socket. In case of a TCP socket, it causes an attempt to establish a new TCP
connection.
• accept() is used on the server side. It accepts a received incoming attempt to
create a new TCP connection from the remote client, and creates a new socket
associated with the socket address pair of this connection.
• send() and recv(), or write() and read(), or sendto() and recvfrom(), are used for
sending and receiving data to/from a remote socket.
Berkeley Sockets API Functions
• close() causes the system to release resources allocated to a socket. In case of
TCP, the connection is terminated.
• gethostbyname() and gethostbyaddr() are used to resolve host names and
addresses.
• select() is used to prune a provided list of sockets for those that are ready to
read, ready to write, or that have errors.
• poll() is used to check on the state of a socket in a set of sockets. The set can
be tested to see if any socket can be written to, read from or if an error
occurred.
• getsockopt() is used to retrieve the current value of a particular socket option
for the specified socket.
• setsockopt() is used to set a particular socket option for the specified socket.