[erlang-questions] How does code:purge/1 know to kill processes?

Samuel samuelrivas@REDACTED
Thu Jun 9 09:49:19 CEST 2016


The processes are killed immediately. That happens, for example, if a
process is in a loop that doesn't involve any external call (since
external calls would load the latest version of the code)

-module(test).
-compile(export_all).

start_process() ->
    spawn_link(fun foo/0).

foo() ->
    timer:sleep(100000),
    foo().


14> c(test).
{ok,test}
15> test:start_process().
<0.81.0>
16> l(test).
{ok,test}
17> l(test).
** exception exit: killed

This doesn't happen if the code has time to reload code by doing an
external call. So if we instead do

-module(test).
-compile(export_all).

start_process() ->
    spawn_link(fun foo/0).

foo() ->
    timer:sleep(100),
    ?MODULE:foo().

26> c(test).
{ok,test}
27> test:start_process().
<0.126.0>
28> l(test).
{module,test}
29> l(test).
{module,test}
30> l(test).
{module,test}
31> l(test).
{module,test}

Unless we are fast enough to load code twice while the process is
lingering in the sleep.


On 9 June 2016 at 09:25, Roger Lipscombe <roger@REDACTED> wrote:
> The documentation for code:purge/1
> (http://erlang.org/doc/man/code.html#purge-1) says "If some processes
> still linger in the old code, these processes are killed before the
> code is removed."
>
> How is "lingering" defined?
>
> Does the VM kill the process when it attempts to invoke the old module?
> Does the VM walk the stack for all processes and kill those that have
> the old code somewhere in their call stack?
> Something else?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



-- 
Samuel



More information about the erlang-questions mailing list