Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Differentiate between shared memory and message passing model in OS.
Shared memory system is a fundamental model of inter-process communication where cooperating processes communicate by establishing a shared memory region within their address space. This approach allows multiple processes to access the same physical memory location for data exchange.
The shared memory concept works on the principle of fastest inter-process communication. When a process wants to initiate communication and has data to share, it establishes a shared memory region in its address space. Another process that wants to communicate must attach itself to the initiating process's shared address space to read the shared data.
Message Passing Model
Message Passing provides a mechanism that allows processes to communicate and synchronize their actions without sharing the same address space. This model is particularly useful in distributed environments where processes run on different machines connected through a network.
For example, chat programs on the World Wide Web use message passing to enable communication between users on different systems.
Message Passing Operations
Message passing provides two fundamental operations ?
Send message ? Process sends data to another process
Receive message ? Process receives data from another process
Messages sent by a process can be either fixed or variable size. Fixed-size messages make system-level implementation straightforward but programming more difficult. Variable-sized messages require more complex system-level implementation but simplify the programming task.
When processes P1 and P2 want to communicate, they need to send and receive messages from each other, establishing a communication link between them.
Architecture Comparison
Key Differences
| Aspect | Shared Memory | Message Passing |
|---|---|---|
| Communication Method | Direct access to shared memory region | Sending and receiving messages through kernel |
| System Architecture | Single processor and multiprocessor systems with common address space | Distributed environments with processes on remote machines connected via network |
| Programming Complexity | Requires explicit synchronization code to handle concurrent access | OS provides built-in communication and synchronization mechanisms |
| Performance | Faster communication with minimal system call overhead | Slower due to kernel involvement in message handling |
| Data Conflicts | Risk of race conditions; requires careful synchronization | No conflicts as each message is independent |
| Memory Usage | Efficient for large data transfers | Better for small data amounts due to message overhead |
| Fault Tolerance | Process failure can affect shared memory region | More resilient as processes are independent |
Use Cases
Shared Memory is ideal for applications requiring high-speed data exchange between processes on the same machine, such as multimedia processing, scientific computing, and database systems where large amounts of data need frequent access.
Message Passing is preferred for distributed applications like web services, client-server architectures, and microservices where processes run on different machines and need reliable, synchronized communication.
Conclusion
Shared memory offers faster communication for processes on the same system but requires careful synchronization. Message passing provides better isolation and works across distributed systems but with higher overhead. The choice depends on system architecture, performance requirements, and data sharing patterns.
