Skip to content

Instantly share code, notes, and snippets.

@leikind
Created December 30, 2011 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leikind/1541632 to your computer and use it in GitHub Desktop.
Save leikind/1541632 to your computer and use it in GitHub Desktop.
-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