0% found this document useful (0 votes)
60 views25 pages

Processes IPC

operating system notes

Uploaded by

Abdul Ahad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views25 pages

Processes IPC

operating system notes

Uploaded by

Abdul Ahad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Processes (IPC)

5th Lecture
Interprocess Communication

• Interprocess communication (IPC) mechanism that will allow processes to


exchange data— that is, send data and receive data from other processes.
• Two types of processes
1. Independent:
A process is independent if it does not share data with any other processes
executing in the system.
2. Cooperating:
A process is cooperating if it can affect or be affected by the other processes
executing in the system. Only these processes can performs IPC.
Why cooperating processes needed?
• Information sharing. Since several applications may be interested in the
same piece of information (for instance, copying and pasting), we must
provide an environment to allow concurrent access to such information.
• Computation speedup. If we want a particular task to run faster, we
must break it into subtasks, each of which will be executing in parallel
with the others. Notice that such a speedup can be achieved only if the
computer has multiple processing cores.
• Modularity. We may want to construct the system in a modular fashion,
dividing the system functions into separate processes or threads.
Models of interprocess
communication
• There are two models of IPC
1. Shared memory
2. Message Passing

• In the shared-memory model, a memory region shared by the


cooperating processes is established. Processes can then exchange
information by reading and writing data to the shared region.
• In the message-passing model, communication takes place using
messages exchanged between the cooperating processes.
Models of IPC
IPC in Shared-Memory Systems
• Shared region established when communication between two
processes is needed.
• Typically, this shred region resides in the address space of the process.
• Processes agreed to protection of shared region, and provide
synchronization in communication.
• Programmer responsibility for writing such code in the application.
Producer consumer problem.
• A producer process produces information that is consumed by a
consumer process.
• For example, a compiler may produce assembly code that is
consumed by an assembler.
• The assembler, in turn, may produce object modules that are
consumed by the loader.
• Shared Memory zones called buffers.
• The unbounded buffer places no practical limit on the size of the
buffer. The bounded buffer assumes a fixed buffer size.
IPC in Message-Passing Systems
• In shared memory, an app programmer should write the code to
achieve successful communication.
• In message passing OS provides IPC.
• Message is passed between two processes similar to chat messenger.
• Messages sent by a process can be either fixed or variable in size.
• Fixed messages have simple system-level implementation and
complex programming
• Must have a Communication link
IPC in Message-Passing Systems
Several features for logically implementing a link and the
send()/receive() operations:

• Direct or indirect communication


• Synchronous or asynchronous communication
• Automatic or explicit buffering

We look at issues related to each of these features next.


Naming

Direct Communication:
• Sender and receiver names are mentioned in the message.
• Exactly and only one link between the two processes.
The send() and receive() primitives are defined as
send(P, message)—Send a message to process P.
receive(Q, message)—Receive a message from process Q.

• The disadvantage is no modularity.


Naming
InDirect Communication:
• The messages are sent to and received from mailboxes.
• mailbox has a unique identification.
• Two processes can communicate only if they have a shared mailbox.

The send() and receive() primitives are defined as


send(A, message)—Send a message to mailbox A.
receive(A, message)—Receive a message from mailbox A.
Problem in Indirect naming method
• Now suppose that processes P1, P2, and P3 all share mailbox A.
Process P1 sends a message to A, while both P2 and P3 executes
receive primitive.
Solution can be:
• Allow a link to be associated with two processes at most.
• Allow at most one process at a time to execute a receive() operation.
• Allow the system to select arbitrarily which process will receive the
message.(e,g round robin)
Who owns the mailbox?
• A mailbox may be owned either by a process or by the operating
system.
• If the mailbox is owned by a process (that is, the mailbox is part of the
address space of the process)
• Sender are users and owner is the receiver of mailbox.
• Mailbox will terminate with process
Mailbox owned by OS
• Independent Existence (in terms of Address Space)
• OS must provide a mechanism that allows a process to do the
following:
• Create a new mailbox.
• Send and receive messages through the mailbox.
• Delete a mailbox.
• The process that creates a new mailbox is the mailbox’s owner.
• The ownership and receiving privilege may be passed to other
processes through appropriate system calls.
Synchronization
• Message passing may be either blocking or nonblocking— also known
as synchronous and asynchronous.
• Blocking send. The sending process is blocked until the message is
received by the receiving process or by the mailbox.
• Nonblocking send. The sending process sends the message and
resumes operation.
• Blocking receive. The receiver process blocks its processing until a
message is available.
• Nonblocking receive. The receiver continues processing, and the
message receiving is handled in the background.
Buffering
• Zero capacity. The queue has a maximum length of zero
• In this case, the sender must block until the recipient receives the
message.
• Bounded capacity. The queue has finite length n; thus, at most n
messages can reside in it.
• The link’s capacity is finite, however. If the link is full, the sender must
block until space is available in the queue.
• Unbounded capacity. The queue’s length is potentially infinite; thus,
any number of messages can wait in it. The sender never blocks.
Examples of IPC Systems
POSIX Shared Memory:
• The portable OS interface can have both IPCs ( i,e shared and message
passing)
• In shared POSIX first create a shared-memory object using the shm
open() system call.
• Once the object is established, the ftruncate() function is used to
configure the size of the object in bytes.
• Finally, the mmap() function establishes a memory-mapped file
containing the shared-memory object.
Mach Message Passing
• The Mach kernel supports the creation and destruction of multiple
tasks, which are similar to processes.
• Messages are sent to, and received from, mailboxes, which are called
ports
• Ports are finite in size and unidirectional.
• Associated with each port is a collection of port rights, (allowable
tasks info)
• The owner is the only task that is allowed to receive messages from
that port.
Pipes
• A pipe provides a channel for two processes to communicate.
• There are two forms of pipes, ordinary and named.
• Ordinary pipes are designed for communication between processes
that have a parent–child relationship.
• Named pipes are more general and allow several processes to
communicate
Pipes in Unix
• UNIX systems provide ordinary pipes through the pipe() system call.
pipe(int fd[])
• Ordinary pipes have a read end and a write end, same as Producer
Consumer problem.
• A parent process can, for example, send data to the pipe using its
write end, and the child process can read it from its read end.
Pipes in Unix
• Named pipes in UNIX are termed FIFOs.
• A FIFO is created with the mkfifo() system call
• It appears as typical files in the file system and is manipulated with
the ordinary open(), read(), write(), and close() system calls.
• It allows bidirectional communication but only half-duplex
transmission is permitted.
• This communication must reside on the same machine.
Pipes in Windows
• Windows systems also provide two forms of pipes, anonymous and
named pipes.
• Anonymous pipes are similar to UNIX ordinary pipes. They are
unidirectional and employ parent–child relationships between the
communicating processes.
• Named pipes offer a richer form of interprocess communication than
the UNIX counterpart, FIFOs.
• Windows FIFOs are full duplex, and communication can be with
different machines and allow either byte- or message-oriented data.
Communication in Client–Server
Systems
• Sockets: it allows two processes on different machines to
communicate over a network.
Remote Procedure Calls
• RPCs abstract the concept of function (procedure) calls in such a way that a
function can be invoked on another process that may reside on a separate
computer. Procedure is in following
1. Client calls client stub or client proxy
2. Client stub packs parameters into a message and perform marshalling.
3. Client OS send message to server using a system call.
4. Server calls server stub of server proxy which de-marshalling the msg.
5. Server OS sends parameters to the procedure for execution and replies
with the same procedure.
RPC
• Stub is a program that temporarily replaces a remote
object or service as if it is local.
• Marshalling is a process in operating systems (OS) that involves
transferring an object from a client to a server

You might also like