The design of the new porject was not past. Somethings I understood wrong. Today I have to modify the design.
Emitting Exit Signals
When a process terminates, it will terminate with an exit reason as explained in Process Termination above. This exit reason is emitted
in an exit signal to all linked processes.
A process can also call the function exit(Pid,Reason). This will result in an exit signal with exit reason Reason being emitted to Pid,
but does not affect the calling process.
Receiving Exit Signals
The default behaviour when a process receives an exit signal with an exit reason other than normal, is to terminate and in turn emit exit
signals with the same exit reason to its linked processes. An exit signal with reason normal is ignored.
A process can be set to trap exit signals by calling:
process_flag(trap_exit, true)
When a process is trapping exits, it will not terminate when an exit signal is received. Instead, the signal is transformed into a message
{'EXIT',FromPid,Reason} which is put into the mailbox of the process just like a regular message.
An exception to the above is if the exit reason is kill, that is if exit(Pid,kill) has been called. This will unconditionally terminate
the process, regardless of if it is trapping exit signals or not.
Receiving Exit Signals
An alternative to links are monitors. A process Pid1 can create a monitor for Pid2 by calling the BIF erlang:monitor(process, Pid2).
The function returns a reference Ref.
If Pid2 terminates with exit reason Reason, a 'DOWN' message is sent to Pid1:
{'DOWN', Ref, process, Pid2, Reason}
If Pid2 does not exist, the 'DOWN' message is sent immediately with Reason set to noproc.
Monitors are unidirectional. Repeated calls to erlang:monitor(process, Pid) will create several, independent monitors and each one will
send a 'DOWN' message when Pid terminates.
A monitor can be removed by calling erlang:demonitor(Ref).
It is possible to create monitors for processes with registered names, also at other nodes.
Emitting Exit Signals
When a process terminates, it will terminate with an exit reason as explained in Process Termination above. This exit reason is emitted
in an exit signal to all linked processes.
A process can also call the function exit(Pid,Reason). This will result in an exit signal with exit reason Reason being emitted to Pid,
but does not affect the calling process.
Receiving Exit Signals
The default behaviour when a process receives an exit signal with an exit reason other than normal, is to terminate and in turn emit exit
signals with the same exit reason to its linked processes. An exit signal with reason normal is ignored.
A process can be set to trap exit signals by calling:
process_flag(trap_exit, true)
When a process is trapping exits, it will not terminate when an exit signal is received. Instead, the signal is transformed into a message
{'EXIT',FromPid,Reason} which is put into the mailbox of the process just like a regular message.
An exception to the above is if the exit reason is kill, that is if exit(Pid,kill) has been called. This will unconditionally terminate
the process, regardless of if it is trapping exit signals or not.
Receiving Exit Signals
An alternative to links are monitors. A process Pid1 can create a monitor for Pid2 by calling the BIF erlang:monitor(process, Pid2).
The function returns a reference Ref.
If Pid2 terminates with exit reason Reason, a 'DOWN' message is sent to Pid1:
{'DOWN', Ref, process, Pid2, Reason}
If Pid2 does not exist, the 'DOWN' message is sent immediately with Reason set to noproc.
Monitors are unidirectional. Repeated calls to erlang:monitor(process, Pid) will create several, independent monitors and each one will
send a 'DOWN' message when Pid terminates.
A monitor can be removed by calling erlang:demonitor(Ref).
It is possible to create monitors for processes with registered names, also at other nodes.