Pergunta

I knew there are several methods to implement IPC. Such as pipe, socket and so on.

Here is my question:

Say we have a parent process A and two child processes B and C.

I knew that if B wants to communicate with C. It needs to use IPC.

Q1: In this case, Are IPC methods limited? To implement this kind of IPC, are there only some types of IPCs can be used? such as It can only use pipe, shared memory but signal.

Q2: If child process want to communicate with its parent, Is IPC needed? (How about B has its child D, If D wants to communicate with A, Is IPC needed?) Q3: If a thread in B and a thread in D, Is IPC needed for these two thread to communicate?

Q4: Same question as Q3, how about two thread one is in child process and the other one is in parent process?

Thanks

Foi útil?

Solução

A1. It depends on your design. A parent can help to establish IPC between its children by allocating necessary IPC structures (pipe, shared memory etc) and by propagating the IPC keys to the children. If the parent makes all the necessary work for the structures allocation and keys propagation, you may use any IPC approach without any restriction. If the parent does not establish IPC between its children or does not share IPC keys among them, you do have a restriction like any other IPC between not related (not forked) processes. In that case, for example, you cannot use a pipe, but still can use a shared memory or a named pipe (think about key or name convention).

A2. If the parent wants to communicate with a child, it can (and should) use IPC, because they are different processes. Since the parent and its children are related processes, any IPC type can be used with no restrictions.

A3. Since the threads belong to different processes, you need to use IPC. What type of IPC should be used? It depends on your design. Answers 1 and 2 attempt to explain it.

A4. Because the threads belong to different processes an IPC is needed. Because the processes are related (parent and child), theoretically any IPC approach can be used.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top