CPI: inter process Communication. The easiest part of the question has already been answered, but it covers much more underneath.
I’m going to take the liberty here and tell you that process is all that occupies the processor to simplify the understanding, okay?
CPI levels vary according to the technology used and the technique for communicating. Let’s discuss a MIMD/processor computational system with process scheduling, from the level I consider most decoupled to what I consider more coupled.
Since we are talking about multiple processes talking to each other, these multiple processes do not necessarily need to be on the same machine. Let’s start with the case that they’re on the same machine.
Communication interfaces
Summary:
Plexity? Uniplex, half-duplex or full duplex
Type of data? Generalized
Assets/liabilities? Assets
Duration: Arbitrary/Lifetime
They are interfaces provided by the operating system itself. They can be Uniplex, half duplex and full duplex. The most typical example of an interface communication Uniplex is the pipeline, more briefly known as pipe, or even by |
for the intimate. How this works?
Take a basic shell script example:
echo "furiosas ideias verdes dormem furiosamente" | sed -e 's/(^| )[aeiou][^ ]* / /g' |
sed 's/ */ /g' | tr -d aeiou
Here, each process works sufficiently separate from each other. There is no memory sharing, nor does one process know of each other’s existence. Underneath, the bash is printing the effect phrase, then feeding the first sed
(which removes words beginning with vowels, leaving a space in place), which then feeds the second sed
(which removes excess space) which only then launches into the tr
delete vowels from the input. The output of this script is:
frss vrds drmm frsmnt
Step by step from example
echo "furiosas ideias verdes dormem furiosamente"
Entree:
Exit:
furiosas ideias verdes dormem furiosamente
sed 's/[aeiou][^ ]* / /g'
Entree:
furiosas ideias verdes dormem furiosamente
Exit:
furiosas verdes dormem furiosamente
sed 's/ */ /g'
Entree:
furiosas verdes dormem furiosamente
Exit:
furiosas verdes dormem furiosamente
tr -d aeiou
Entree:
furiosas verdes dormem furiosamente
Exit:
frss vrds drmm frsmnt
Other interprocess communications by interfaces
The pipe. That one pipe is also known as pipe anonymous, for he was not named. There is also the pipe named. On Unix system, you create a pipe appointed through command mkfifo
, then you put a process to write on pipe and another to read from it, as if it were a traditional file system file.
Another model is also the socket. A program opens a socket and goes into listening mode, then another program connects and the two go on speaking through socket.
MPI
Summary:
Plexity? Full duplex
Type of data? Generalized
Assets/liabilities? Assets
Duration: Arbitrary/Lifetime
MPI is a kind of communication interface, but here there is a greater cohesion, there is a more intense coupling. It can also be said that this is multi computer, but it works very well with only one computer.
Imagine that you need to know how a molecule if structure given the pH and temperature of human blood (remnants of the time where he worked at CENAPAD-UFC). This molecule is too big, with almost independent parts of each other, so you can separately compute the behavior of its structures, arrive at a position of electro-stabilityand then update the information obtained by the other processing to refine its positioning.
This exchange of values is commonly done by sending messages in a processing type BSP.
BSP in fifteen seconds: large independent processing pieces that are synchronized and exchange information with each other from time to time.
Example of BSP in this answer, through the processes in the ordering networks.
Shared memory
Summary:
Plexity? Full duplex
Type of data? Generalized
Assets/liabilities? Liabilities
Duration: Arbitrary
Here two or more processes share part of the computer’s memory. They write in the common area, they read from the common area, but also have their private area. MPI can be mounted on top of that.
It is usually at this level that the programmer begins to worry about semaphores/mutex/monitors themselves. Before, he just knows that these things exist.
This sharing of data allows greater agility in execution, but it also requires more control from the programmer. Unlike communication by interface, this here does not allow launching an event for the other process to take action: here, communication is totally passive.
I don’t need or should talk to the other process: look, data! The other process just takes the data.
Shared variables
Summary:
Plexity? Full duplex
Type of data? Generalized
Assets/liabilities? Liabilities
Duration: Lifetime
Okay, some would argue that this is a kind of Shared Memory, others would argue that I’m making up that name. And, in fact, I can’t remember what the right name is, but that name comes in handy.
Here, not only is there a shared memory space between several processes, but in fact all memory is shared. Sharing is so large that even by the same names the variables meet. This is the IPC model in threads.
Signal sending
Summary:
Plexity? Uniplex
Data type? Signal/byte
Assets/liabilities? Assets
Duration: Moment
Who has never received a SIGSEGV
when programmed in C?
SIGSEGV
is also known for Segmentation fault, or segmentation failure. This is a unix signal sent by operating system saying that you accessed an area of memory out of expected (ended up violating the program memory segment).
It has other very characteristic signs that we use:
- pause signal (CTRL+Z on terminal;
SIGSTOP
)
- interrupt signal (CTRL+C on terminal;
SIGINT
)
- sign of death (already given
kill -9 <PID>
in some process? SIGKILL
)
Some signals can be intercepted, others not. SIGKILL
and SIGSTOP
, if I’m not mistaken, they’re not interceptable. I don’t remember if it is possible to send signals from any program to any program, but I am sure that any ancestral program can send a signal to any of its descendants. Wtrmute shows in an excellent way in this answer how to use messaging within the process tree, from ancestor to descendant and vice versa.
Has a specific question on signs
Via file
Summary:
Plexity? Half-duplex
Type of data? Generalized
Assets/liabilities? Liabilities
Duration: Arbitrary
Write to a file, wait for another process to read. Pig and straight to the subject. If the file is resident of RAM (RAM-FS), it will be faster.
It could also work well in case the OS takes too long to flush and allows "reading" of what is cached files by other processes, it might not be as bad of performance.
The advantage of this method is that communication information is persisted in the case of abrupt termination of the reading process.
Via database
Summary:
Plexity? Half-duplex
Type of data? Generalized
Assets/liabilities? Liabilities
Duration: Arbitrary
Similar to IPC per file, but DBMS can optimize for the table to stay in RAM while writing/reading more efficiently than reading in the file cache before flush.
Latch file
Summary:
Plexity? Uniplex
Type of dice? Boolean
Assets/liabilities? Liabilities
Duration: Arbitrary
I remembered that kind of communication when I wrote that answer.
In short: when you are in a multitasking environment and need to ensure the integrity of some file on the system, having no fixed server to control this situation, a latch file.
The following excerpt exemplifies how this strategy works in the environment git
:
In case, as there is no server waiting to hear a message, a process git
needs to decide for yourself by observing the environment (OS included as part of the environment) whether it can make critical changes or not. So he makes the following call to the operating system:
So, please, create for me the file .git/index.lock
? Returns me success if it is only if I was the one who managed to create this file, or if it already exists return me failure
For which, there are two answers that the OS can provide:
It’s here, little one git
, you created the file
Or, in case the file already exists (or just created by another process in parallel):
Hey, pet! This file already exists!
If the file previously exists (and therefore the error occurred), the git
aborts gracefully with that message you’ve been received.
If the file was created (and therefore successful), the git
is happy in its processing and, when you have finished the required activity, will remove the lock file.
Environment variable
Summary:
Plexity? Uniplex
Type of data? Text
Assets/liabilities? Liabilities
Duration: Creation of the child process
In shell-script, in several corners we need to do things like this:
export PATH=/bin:/usr/bin:$HOME/bin
./meu_script.sh
That’s one way to get on the show meu_scrpit.sh
the variable $PATH
. Note: if the export
is omitted, the value of the changed variable will not be passed to the child process.
These variables are only passed from the parent process to the child process, and if I’m not mistaken the values are set at the time of doing the fork
.
Code of return
Summary:
Plexity? Uniplex
Data type? Byte
Assets/liabilities? Liabilities
Duration: Termination of child process
When a child process ends, he can notify the father if everything was normal or if there was a failure during the execution. The default is to return 0
when there is no error (successful execution) and with a code other than 0
when there is error, and each value would correspond to a different error.
This allows a calling program to make execution flow decisions conditioned on the success or failure of the child program. The error code also allows you to inform the calling program what the problem was (or the person running the program in hand).
Perhaps it’s the case that you consolidate a little more what you know before you ask the questions... Because I have the impression that the answers will have a lot of overlap. By the way, I think it fits the tag [tag:multithreading] in all these questions.
– bfavaretto
@bfavaretto thinks of a guy who this time really doesn’t know anything about it? It’s me. Most of the time I ask on the website, it’s because I already know the answer, but this time it was different. I apologize if I ended up formulating something in a bad way, but is that I saw nothing on the site talking directly about the subject.
– Wallace Maxters
@bfavaretto I was even wanting to ask what was System V, because I had never heard of it before.
– Wallace Maxters
It’s not that the questions are poorly formulated, it’s that you’re casting a lot of related questions. Maybe you could merge some of them. But I’m also not an expert in the field, I may not be able to. My tip is just to hold the rhythm a little ;)
– bfavaretto
@bfavaretto if that’s the case, we can close the questions. I don’t care about that. I usually really like to separate each term into a question. But maybe we can at least mark it as duplicate, to have more references.
– Wallace Maxters
@bfavaretto I’m really "riding". I’m running back and forth like crazy to know what’s behind that question I asked about msg_ in php. I don’t want to try to implement anything without knowing right if what I’m thinking about functions is right.
– Wallace Maxters
IPC would be the [Communication between processes] (https://pt.wikipedia.org/wiki/Comunica%C3%A7%C3%A3o_entre_processos)
– Don't Panic
Out of curiosity, what are you trying to implement? As I said, I don’t understand much of the subject, but I would think twice before dealing with multiple threads or processes with PHP. Doesn’t seem like the proper language for it.
– bfavaretto
@bfavaretto agree with you. PHP actually has several limitations when controlling processes (when using Apache primarily). The very idea was to understand how those work message queues php natives I showed in the other question, and how this relates to the terms : System V, IPC, Shared memory, semaphores and the like...
– Wallace Maxters
I found this link. I’ll check it out later.
– Wallace Maxters
How to use IPC wrong: https://answall.com/a/45330/64969
– Jefferson Quesado