Restarting erlang process and preserving state

后端 未结 3 1322
清酒与你
清酒与你 2021-02-06 07:01

I have a supervisor process which starts number of child processes. Currently when the child dies I spawn a new process with new Pid. This means I loose the state information of

3条回答
  •  星月不相逢
    2021-02-06 07:35

    Using ETS tables is probably the way to go for keeping the state. Vinoski's article discusses how to make it possible to restart a crashed process while keeping the ETS table data.

    As @user30997 points out the data in the table may actually be the reason the process crashed, so on restart you might want to validate the table (or set a limit on how many times the process will be restarted...)

    For associating processes with id's you should take a look at gproc which is great for this.

提交回复
热议问题