summaryrefslogtreecommitdiff
path: root/erlang/monitor_doctor.erl
diff options
context:
space:
mode:
authorGuillermo Ramos2012-05-11 00:49:36 +0200
committerGuillermo Ramos2012-05-11 00:49:36 +0200
commit5d8c20c0a91dbd58a1676581c4374ecb67e639a7 (patch)
tree15ef8efe0a214a088274c1db58408caeff29fdd2 /erlang/monitor_doctor.erl
parent67a898893884f229d64886a220ba422dd0d66e78 (diff)
download7l-5d8c20c0a91dbd58a1676581c4374ecb67e639a7.tar.gz
[Erlang] Día 3 (1/2)
Diffstat (limited to 'erlang/monitor_doctor.erl')
-rw-r--r--erlang/monitor_doctor.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/erlang/monitor_doctor.erl b/erlang/monitor_doctor.erl
new file mode 100644
index 0000000..537f59a
--- /dev/null
+++ b/erlang/monitor_doctor.erl
@@ -0,0 +1,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().