[erlang-questions] Atomically replace named process?

Sergej Jurecko sergej.jurecko@REDACTED
Wed Jun 11 20:19:07 CEST 2014

If you are registering the process manually this method will work.

The problem you might run into is the old process dying just before someone is calling it. You would have to cycle off the process by calling unregister manually and wait for some time to handle calls that are still using the old PID.

If your gen_server init looks like this:

init() ->
case catch register(name) of
  ok ->
  _ ->

Then call, getpid functions:

call(Msg) ->

% The returned PID may get unregistered before it is used. 
% This is why the gen_server must unregister and wait for a timeout before dying.
getpid() ->
	case whereis(name) of
		undefined ->
			case gen_server:start(….) of
				{error,normal} ->
					% some other process won the race to register itself.
				{ok,Pid} ->
				    % this start call won the race
		Pid ->

On 11 Jun 2014, at 09:17, Roger Lipscombe <roger@REDACTED> wrote:

> I've got a gen_server with a particular name. I've got a bunch of
> other processes calling and casting to it, by name.
> Can I spin up another gen_server, and have the name transferred
> without anyone noticing? That is: can I redirect the calls and casts
> to the new process without interruption?
> -- 
> Roger.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list