exit in fun running via timer:apply_interval/4

Bengt Kleberg <>
Tue Jun 7 13:11:59 CEST 2005


On 2005-06-03 20:53, Reto Kramer wrote:
> Folks,
> 
> I'm looking for the best (elegant) way to make sure that if there's an 
> exit in the Mod:Fun that I run via timer:apply_interval/4, the "parent" 
> process (the one that scheduled the timer) will receive the exit 
> message, so I can programmatically react to it (and e.g. shutdown my 
> system).
> 
> I'm sure someone out there has an elegant solution.

i do not have a solution. instead i have a follow-up question:

what does the following from the man page of the timer module mean?

         An interval timer, i.e. a timer created by evaluating any of 
the  func-
        tions apply_interval/4, send_interval/3, and send_interval/2, is 
linked
        to the process towards which the timer performs its task.

i interpreted it to mean that the process that called 
timer:apply_interval will be linked to the (temporary) process doing the 
  module:function() supplied as argument to apply_interval/4.
this is not the case, so what does it really mean?
who is linked, and to whom?


bengt, who has included a little test module to play with when 
investigating this problem.


-module(interval).
-export([main/1, crashing/0]).


main(_) ->
	timer:apply_interval(1000,  interval,  crashing,  []),
	loop(0),
	init:stop().

crashing() ->
	io:fwrite("~w~n", [erlang:self()]),
	erlang:exit(crashing).

loop(N) ->
	receive
	Something ->
		io:fwrite("~w~n", [Something])
	after 500 ->
		io:fwrite("~w~n", [N])
	end,
	loop(N+1).



More information about the erlang-questions mailing list