Lecture 3
Lecture 3
Architecture
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.
Characteristics:
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.
• 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