0% found this document useful (0 votes)
7 views19 pages

Lecture 3

The document discusses processes as fundamental components of software architecture, highlighting their characteristics, lifecycle, and the importance of inter-process communication (IPC) through message passing. It explores various IPC techniques such as pipes, message queues, shared memory, and sockets, as well as their applications in distributed systems. The conclusion emphasizes the role of message passing in enabling communication between independent processes in multitasking and distributed environments.

Uploaded by

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

Lecture 3

The document discusses processes as fundamental components of software architecture, highlighting their characteristics, lifecycle, and the importance of inter-process communication (IPC) through message passing. It explores various IPC techniques such as pipes, message queues, shared memory, and sockets, as well as their applications in distributed systems. The conclusion emphasizes the role of message passing in enabling communication between independent processes in multitasking and distributed environments.

Uploaded by

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

Processes and Message Passing in Software

Architecture

Prepared By Shafiq Ahmad


Contents:

• Introduction to Processes in Software


Architecture
• What are Processes?
• Message Passing: Introduction and Models
• Inter-Process Communication (IPC)
Techniques
• Distributed Systems and Message Passing
• Synchronization in Message Passing
• Practical Use Cases for Message Passing
• Conclusion
Introduction to Processes in Software Architecture

• In a computer system, processes are fundamental building blocks of


multitasking. A process is an instance of a running program that has
its own memory space, execution path, and system resources.
Unlike threads, processes do not share memory with other
processes. This isolation ensures security and stability but also
brings challenges in inter-process communication (IPC).

• In this lecture, we'll focus on the concept of processes and how


they communicate using message passing, one of the key IPC
mechanisms.
1. What are Processes?
• A process is a self-contained execution environment. It has:
• Its own memory space (isolated from other processes).
• A unique process identifier (PID).
• A code segment, data segment, stack, and heap

Characteristics of Process:
• Each process runs independently, meaning it doesn't share memory or data
with other processes.
• Processes are more heavyweight than threads, as they require more
resources to create and maintain.
• Processes offer greater security due to memory isolation, which prevents
accidental overwriting of data by other processes.
2. Life Cycle of process
Creation: A process is created when an executable program is
loaded into memory.
Execution: The process enters the running state, where
instructions are executed.
Termination: After completing execution, the process is
terminated and its resources are freed.
Process Creation and Management:
• Processes can create child processes using system
calls like fork() in UNIX-based systems.
• Parent processes can communicate with child
processes, but data sharing is not automatic.
3. Introduction to Message Passing
Since processes do not share memory, they need a method to
communicate and exchange data. Message passing is one of the
primary IPC techniques that enables communication between
processes running on the same machine or across a network.

Message Passing Characteristics:


• Data Exchange: Processes exchange messages that can contain
data, commands, or signals.
• Decoupling: Processes remain independent from one another, as no
direct memory sharing occurs.
• Synchronization: Message passing can be synchronous (blocking) or
asynchronous (non-blocking), depending on the implementation.
Message passing can happen at different levels:
Intra-process communication (on the same machine):
E.g., via pipes, message queues, and shared memory.

Inter-process communication (across networked


systems):
E.g., via sockets, RPC (Remote Procedure Call), and
distributed messaging systems.
4. Models of Message Passing
1. Synchronous Message Passing
In synchronous communication, the sender and receiver must be
synchronized for the message to be transferred. The sender waits (blocks)
until the receiver is ready to receive the message.

Characteristics:

• Sender and receiver are tightly coupled.


• Useful in cases where real-time data integrity is required.
• More complex as it may cause deadlocks or reduced performance due to
waiting.
• Example in UNIX: Using pipe() system call in C for message passing
between parent and child processes.
4. Models of Message Passing (cont)
2. Asynchronous Message Passing
In asynchronous communication, the sender can send the message and
continue executing without waiting for the receiver to be ready. Similarly, the
receiver can collect the message whenever it is ready.

Characteristics:
• Sender and receiver are decoupled.
• Suitable for distributed systems where network delays or interruptions are
common.
• Non-blocking operations allow better resource utilization and
performance.
• Example in UNIX: Using message queues with msgsnd() and msgrcv()
system calls for asynchronous communication.
5. Inter-Process Communication (IPC) Techniques
There are several mechanisms used for inter-process communication. These vary in
their complexity, performance, and use cases.

1. Pipes
Pipes are a unidirectional communication channel that allows data transfer between
related processes (e.g., parent and child). They are generally used for transferring
small amounts of data.
Anonymous Pipes: Used for communication between processes that are related, e.g.,
parent-child.
Named Pipes (FIFOs): Used for communication between unrelated processes. They are
identified by a name in the filesystem.

Limitations:
• Only allow one-way communication.
• Not suitable for large data transfers.
5. Inter-Process Communication (IPC) Techniques (cont)
2. Message Queues
Message queues are an IPC mechanism that allows asynchronous
communication between processes by sending and receiving
messages. Messages are stored in a queue until they are retrieved.

Benefits:
• Messages are stored until the receiver is ready to retrieve them.
• Suitable for asynchronous communication.

Drawbacks:
• Overhead of copying messages into and out of the queue.
• Limits on the number of messages or size of the queue may exist.
5. Inter-Process Communication (IPC) Techniques (cont)
3. Shared Memory
Although message passing doesn't use shared memory, shared
memory itself is an important IPC mechanism where processes
can share a block of memory. This is the fastest IPC method but
requires careful synchronization (e.g., using semaphores).

Benefits:
• Fastest IPC mechanism due to no data copying between
processes.
Drawbacks:
• Synchronization overhead to avoid race conditions.
5. Inter-Process Communication (IPC) Techniques (cont)
4. Sockets
Sockets are used for communication between processes over a
network. They are essential for inter-network communication between
processes running on different machines.
TCP Sockets: Provide a reliable, connection-oriented communication
protocol.
UDP Sockets: Provide a faster, connectionless communication protocol
but without guaranteed delivery.

Benefits:
• Suitable for both local and network communication.
• Highly scalable and flexible for distributed systems.
6. Distributed Systems and Message Passing
In distributed systems, message passing is crucial for communication between processes running on
different machines across a network.

Remote Procedure Call (RPC)


RPC allows a process to invoke a procedure (function) on a remote machine as if it were local. The
system takes care of sending the arguments to the remote machine, executing the function, and
returning the result.

Message-Oriented Middleware (MOM)


Middleware solutions like RabbitMQ, Kafka, and ZeroMQ enable message-based communication
between distributed systems. They handle message delivery, queue management, and fault tolerance in
distributed environments.

Publish-Subscribe (Pub-Sub) Model


In a Pub-Sub model, processes (clients) subscribe to topics of interest. A publisher sends messages to a
broker, and subscribers receive relevant messages. This model is common in distributed messaging
systems.
7. Synchronization in Message Passing
Synchronization is an essential consideration in message passing, particularly when
processes communicate asynchronously or concurrently.

Blocking vs. Non-Blocking Communication


• Blocking (Synchronous) Communication: A process waits for an operation to
complete before proceeding (e.g., the sender waits until the message is received).
• Non-Blocking (Asynchronous) Communication: A process continues executing
immediately after initiating communication, without waiting for the result.

Deadlock and Starvation


• Deadlock: Occurs when two or more processes are waiting indefinitely for
resources that each holds, leading to a stalemate.
• Starvation: When one process continuously waits for resources while other
processes get access to them, causing indefinite delay.
Proper design using timeouts, priority handling, or resource ordering can prevent
these issues.
8. Practical Use Cases for Message Passing
Client-Server Architecture: Message passing enables communication
between clients and servers. For example, a web server (process)
receives requests from clients, processes them, and sends back
responses.

• Distributed Databases:
In distributed database systems, different database instances
communicate via message passing to ensure data consistency
across different nodes.

• Microservices Architecture:
In microservices, each service is often an independent process.
They use message passing, often through a message broker (like
Kafka or RabbitMQ), for communication.
9. Conclusion

In summary, processes are self-contained execution


units that require message passing for communication
in modern multitasking and distributed systems.
Message passing decouples processes and allows them
to remain independent, while providing flexibility in
both local and networked environments.

You might also like