[erlang-questions] Programming question

Richard Carlsson richardc@REDACTED
Wed Jan 24 15:53:44 CET 2007


Sean Hinde wrote:
> Hi,
> 
> A quick question for Erlang gurus out there.
> 
> I have two processes A and B. B spends most of its life in a series  
> of gen_server calls towards A:
> 
> loopB(PidA, S) ->
>       Res = gen_server:call(PidA, {op, stuff}),
>       S1 = process(Res, S),
>       loopB(PidA, S1).
> 
> The question is how do I set things up so that if A dies B is killed?

Assuming that normal linking of B to A does not work (e.g. if B is
trapping exits, does not accept an exit message in the waiting state,
and you can't change the code of A and B), you could spawn a small
simple watchdog process, and link it to both A and B. It should wait
for the termination of either of them. If A dies, the watchdog kills
B by brute force, i.e., exit(B, kill). If B dies, the watchdog dies
with it, quietly.

Or you could go the whole OTP hog and use a full supervisor model,
as Uffe suggested.

     /Richard




More information about the erlang-questions mailing list