(emacs@aleksio-mobile)1> self(). <0.36.0> (emacs@aleksio-mobile)2> erlang:link(c:pid(0,777,0)). ** exception error: no such process or port in function link/1 called as link(<0.777.0>) (emacs@aleksio-mobile)3> self(). <0.39.0> (emacs@aleksio-mobile)4> flush(). ok (emacs@aleksio-mobile)5> erlang:monitor(process, c:pid(0,777,0)). #Ref<0.0.0.43> (emacs@aleksio-mobile)6> self(). <0.39.0> (emacs@aleksio-mobile)7> flush(). Shell got {'DOWN',#Ref<0.0.0.43>,process,<0.777.0>,noproc} ok (emacs@aleksio-mobile)8>
-module(testm). -export([start_m/0, stop_m/1, loop/1]). start_m() -> erlang:spawn_monitor(?MODULE, loop, [self()]). stop_m(Ref) -> erlang:demonitor(Ref). loop(Shell) -> receive kill -> exit(kill); reason -> exit("Another reason"); Msg -> Shell ! {get_msg, Msg} end.
(emacs@aleksio-mobile)2> {Pid, Ref} = testm:start_m(). {<0.43.0>,#Ref<0.0.0.62>} ### <0.43.0>, #Ref<0.0.0.62> (emacs@aleksio-mobile)3> Pid ! hello. hello ### (emacs@aleksio-mobile)4> flush(). Shell got {get_msg,hello} Shell got {'DOWN',#Ref<0.0.0.62>,process,<0.43.0>,normal} ok ### {get_msg,hello} ### normal (emacs@aleksio-mobile)5> f(Pid), f(Ref). ok ### Pid Ref ### (emacs@aleksio-mobile)6> {Pid, Ref} = testm:start_m(). {<0.48.0>,#Ref<0.0.0.77>} (emacs@aleksio-mobile)7> Pid ! kill. kill (emacs@aleksio-mobile)8> flush(). Shell got {'DOWN',#Ref<0.0.0.77>,process,<0.48.0>,kill} ok (emacs@aleksio-mobile)9> f(Pid), f(Ref). ok (emacs@aleksio-mobile)10> {Pid, Ref} = testm:start_m(). {<0.53.0>,#Ref<0.0.0.91>} (emacs@aleksio-mobile)11> Pid ! reason. reason (emacs@aleksio-mobile)12> flush(). Shell got {'DOWN',#Ref<0.0.0.91>,process,<0.53.0>,"Another reason"} ok (emacs@aleksio-mobile)13> testm:stop_m(Ref). true (emacs@aleksio-mobile)14>
Source: https://habr.com/ru/post/114812/
All Articles