-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkiller.erl
52 lines (47 loc) · 1.31 KB
/
killer.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-module(killer).
-export([start/0]).
start() -> spawn(fun() -> kill() end).
kill() ->
receive
stop -> io:format("the killer has been stopped~n");
{Pid, force} -> exit(Pid, kill),
kill();
Pid -> exit(Pid, "You have been killed"),
kill()
end.
% Esempio di esecuzione:
%
% > c(killer).
% {ok,killer}
% > K = killer:start().
% <0.89.0>
% > self().
% <0.82.0>
% > K ! <0.82.0>.
% ** exception exit: "You have been killed"
% > self().
% <0.92.0>
% > is_process_alive(K).
% true
%
% process_flag(trap_exit, true).
% false
% > K ! self().
% <0.92.0>
% > receive {'EXIT', Pid, Why} -> {Pid, Why} end.
% {<0.89.0>,"You have been killed"}
% Dopo aver impostato trap_exit a true, il segnale di uscita inviato dal killer
% viene trasformato in un semplice messaggio inviato alla mailbox.
% Dalla documentazione ufficiale scopriamo però che:
% "If Reason is the atom kill, that is, if exit(Pid, kill) is called, an untrappable
% exit signal is sent to the process that is identified by Pid, which unconditionally
% exits with exit reason killed"
% Quindi esiste un segnale di uscita che è unstoppable, infatti:
% > c(killer).
% {ok,killer}
% > K = killer:start().
% <0.89.0>
% > process_flag(trap_exit, true).
% false
% > K ! {self(), force}.
% ** exception exit: killed