Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart child with custom state using Erlang OTP supervisor behaviour?

I'm using OTP supervisor behaviour to supervise and restart child processes. However when the child dies I want to restart it with the same state it had before the crash.

If I write my own custom supervisor, I can just receive {EXIT,Pid,Reason} message and act upon it. When using OTP supervisor behaviour however it is all managed by OTP and I have no control over it. The only callback function I implement is init.

Is there any standard approach in case like this? How to customise the state of a child being restarted dynamically by the otp supervisor? How to get Pid of the terminating process using OTP? Or maybe its possible to get the state of the child just before termination, and then restore the child to the same state it had before it crashed?

like image 903
Mark Avatar asked Nov 26 '12 10:11

Mark


1 Answers

Possibly restart with same state is not good idea. Probably wrong state lead process to crash and if you restart with same state, it will crash again. But if you want this, use external resource to keep it (like ets or mnesia).

like image 196
danechkin Avatar answered Nov 15 '22 23:11

danechkin