There are two commons ways to follow up what is going on with a Erlang process: links and monitors. The first one causes linked processes to be shutdown together if one of the linked processes terminates abruptly. The second, only notifies what happened to the other process.
To see that happening, let’s create a new process (outer) that spawns a third one (inner). The last process can either exit forcefully when the explode flag is true, or normally otherwise. In both cases, this will only happen after 5 seconds.
While spawning a new process in the shell, lets also monitor it, so we can receive status messages.
When spawning the outer process with the flag as true, you can see that the inner process is also being spawned. After 5 seconds, they are not running anymore, as showed by the message that the shell received:
It is good to notice that when two processes are linked, and one of the exits normally, the other one is not brought down. That becomes evident when using the flag as false. The processes will be started in the same way as before, but outer, who is also monitoring inner, receives a message notifying that inner went down, and therefore gets out of the receive block and also exits normally.
trap_exit to true, you can change the link behavior. With that, when using :erlang.process_flag, exit signals arriving to a process are converted to messages. To see that in action, let’s do a small change to the previous example. inner will always exit abruptly, and outer is not monitoring inner anymore, but instead trapping the exit signal.
As you can see, the exit signal was converted to a message starting with the
One last thing is that you can force a process to be killed by sending the
:kill atom to it:
- Services Version Lock with Docker and Jenkins
- Erlang, Elixir and a simple Supervisor
- Tips for your Distributed Project Inception or Meeting
- Problems with Branches per Environment
- Useful UNIX Signals (SIGQUIT, SIGSTOP, SIGCONT)
- Using xargs to Parallelize Tasks
- Automatically Build and Deploy the Blog
- Trunk Based Development with Multiple Services
- Integration testing for nginx Routes
- Efficient Timer using a Circular Buffer
- RFID, Dryers, and IoT