Created
December 30, 2011 21:50
-
-
Save leikind/1541632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(kill). | |
-export([kill_demo/0]). | |
listen() -> | |
receive | |
Message -> io:format("~p has caught a system message: ~p~n~n", [self(), Message]), | |
listen() | |
after 1000 -> | |
io:format("I, ~p, live on~n", [self()]), | |
listen() | |
end. | |
kill_demo() -> | |
Pid = spawn_link(fun()-> | |
process_flag(trap_exit, true), | |
listen() | |
end), | |
% this will fail, the recipient process traps all exit signals | |
timer:sleep(3000), | |
io:format("Sending exit(Pid, please_die) ~p to ~n", [Pid]), | |
exit(Pid, please_die), | |
% "The kill reason acts as a special signal that can't be trapped." | |
% this will succeed | |
timer:sleep(4000), | |
io:format("Sending exit(Pid, kill) ~p to ~n", [Pid]), | |
exit(Pid, kill). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment