Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared memory and IPC [closed]

I was reading a tutorial about shared memory and found the following statement: "If a process wishes to notify another process that new data has been inserted to the shared memory, it will have to use signals, message queues, pipes, sockets, or other types of IPC.". So what is the main advantage of using shared memory and other type of IPC for notifying only instead of using an IPC that doesn't need any other IPC type to be used, like message queue and socket for example?

like image 357
user670324 Avatar asked Mar 25 '11 18:03

user670324


People also ask

Is shared memory important for IPC?

Inter Process Communication through shared memory is a concept where two or more process can access the common memory. And communication is done via this shared memory where changes made by one process can be viewed by another process.

What is IPC explain shared memory method of process communication?

IPC is the way by which multiple processes or threads communicate among each other. IPC in OS obtains modularity, computational speedup and data sharing. Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.

Is IPC faster than shared memory?

The IPC shared semaphore facility provides process synchronization. Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated.

What is the difference between message passing and shared memory in IPC?

Message passing is a time consuming process because it is implemented through kernel (system calls). In shared memory make sure that the processes are not writing to the same location simultaneously. Message passing is useful for sharing small amounts of data so that conflicts need not occur.

What are the two types of IPC techniques?

Synchronization in Interprocess Communication The two types of semaphores are binary semaphores and counting semaphores.

Which one is the shared memory technique used in IPC?

Two main methods for inter-process communication are shared memory and message passing. In the shared memory method, two processes communicate with each other using common shared memory. shmget(), shmat(), shmdt(), shmctl() are the commonly used system calls in the shared memory method.


1 Answers

The distinction here is IPC mechanisms for signalling versus shared state.

Signalling (signals, message queues, pipes, etc.) is appropriate for information that tends to be short, timely and directed. Events over these mechanisms tend to wake up or interrupt another program. The analogy would be, "what would one program SMS to another?"

  • Hey, I added a new entry to the hash table!
  • Hey, I finished that work you asked me to do!
  • Hey, here's a picture of my cat. Isn't he cute?
  • Hey, would you like to go out, tonight? There's this new place called the hard drive.

Shared memory, compared with the above, is more effective for sharing relatively large, stable objects that change in small parts or are read repeatedly. Programs might consult shared memory from time to time or after receiving some other signal. Consider, what would a family of programs write on a (large) whiteboard in their home's kitchen?

  • Our favorite recipes.
  • Things we know.
  • Our friends' phone numbers and other contact information.
  • The latest manuscript of our family's illustrious history, organized by prison time served.

With these examples, you might say that shared memory is closer to a file than to an IPC mechanism in the strictest sense, with the obvious exceptions that shared memory is

  1. Random access, whereas files are sequential.
  2. Volatile, whereas files tend to survive program crashes.
like image 117
Andres Jaan Tack Avatar answered Sep 22 '22 00:09

Andres Jaan Tack