1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
-module(monitor_doctor).
-export([loop/0]).
loop() ->
process_flag(trap_exit, true),
receive
die -> exit(mon);
{monitorize, Doctor} ->
io:format("Monitor: monitoring ~p.~n", [Doctor]),
link(Doctor);
new_doc ->
io:format("Monitor: starting new doctor.~n"),
register(doc, spawn_link(doctor, loop, [])),
doc ! {monitorize, self()},
doc ! new_rev;
{'EXIT', From, _} ->
io:format("Monitor: doctor ~p died, restarting.~n", [From]),
self() ! new_doc
end,
loop().
|