monitor.erl

text/x-erlang monitor.erl — 1 KB

Continguts del fitxer

-module(monitor).

-compile(export_all).

start(Pid) ->
    spawn(?MODULE, monitor, [Pid]).

monitor(Pid) ->
    io:format("Monitoritzan al pacient ~p. Constants estables.~n", [Pid]),
    erlang:monitor(process,Pid),
    receive
        {'DOWN', Ref, process, Pid,  normal} ->
            io:format("Monitor: ~p diu que  ~p ha mort per causes naturals~n",[Ref,Pid]);
        {'DOWN', Ref, process, Pid,  Motiu} ->
            io:format("Monitor: ~p diu que  ~p ha mort per ~p~n",[Ref,Pid,Motiu]);
        UnAltre ->
            io:format("Monitor rep <~p>~n", [UnAltre])
    end.