[erlang-questions] what is trap_exit business, process_flag(trap_exit, true)

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Apr 24 14:11:03 CEST 2008


On Wed, Apr 23, 2008 at 09:21:41PM -0400, db wrote:
> In my gen_server:init function, I spawn client processes onto remote
> nodes using proc_lib:spawn_link(N, M, F, A).  Before I spawn any
> process on to remote nodes, I have placed process_flag(trap_exit,
> true).  But when I do exit kill/shutdown in the shell, my gen_server
> and all the remote client processes are terminated mercilessly.  I
> thought process_flag(trap_exit, true) supposed to prevent the whole
> thing from crashing.  Are these kill/shutdown type of exits trappable
> or only 'EXIT'?
> 

It is the spawned processes that need to execute
process_flag(trap_exit, true). That property is
not inherited at spawn.

See http://www.erlang.org/doc/reference_manual/part_frame.html,
section 10, esp. 10.4-7.

> (b@REDACTED)8> exit(pid(0,147,0)).
> ** exception exit: <0.147.0>
>      in function  exit/1
>         called as exit(<0.147.0>)
> 
> (b@REDACTED)9> exit(pid(0,147,0), kill).
> true
> 
> (b@REDACTED)10> exit(pid(0,182,0), shutdown).
> true
> 
> (a@REDACTED)9>
> =ERROR REPORT==== 23-Apr-2008::19:54:52 ===
> ** Generic server clnt_sup terminating
> ** Last message in was {'EXIT',<5679.182.0>,shutdown}
> ** When Server state == {ets_pid,{clnt,loop,[<0.6396.0>]}}
> ** Reason for termination ==
> ** {'module could not be loaded',[{ets_pid,tab2list,[]},
>                                   {clnt_sup,terminate,2},
>                                   {gen_server,terminate,6},
>                                   {proc_lib,init_p,5}]}
> Thank you,
> hoping to get some answers from erlang mailing list, people in IRC are
> very helpful.
> -- 
> rk
> 
> That which we persist in doing becomes easier for us to do; not that
> the nature of the thing itself is changed, but that our power to do is
> increased.
> -Ralph Waldo Emerson
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list