[erlang-questions] monitor/2

Ulf Wiger ulf@REDACTED
Sun Mar 16 22:08:45 CET 2014

Just as an aside, gproc now has extended monitoring functionality:

monitor(Key::key(), Type::monitor_type()) -> reference()

monitor_type() = info | standby | follow

monitor a registered name monitor(Key, info) works much like erlang:monitor(process, Pid), but monitors a unique name registered via gproc. A message, {gproc, unreg, Ref, Key} will be sent to the requesting process, if the name is unregistered or the registered process dies. If there is a standby monitor (see below), a message {gproc, {failover, ToPid}, Ref, Key} is sent to all monitors. If the name is passed to another process using give_away/2, the event {gproc, {migrated, ToPid}, Ref, Key} is sent to all monitors.

monitor(Key, standby) sets up the monitoring process as a standby for the registered name. If the registered process dies, the first standby process inherits the name, and a message {gproc, {failover, ToPid}, Ref, Key} is sent to all monitors, including the one that inherited the name.

If the name is not yet registered, the unreg event is sent immediately. If the calling process in this case tried to start a standby monitoring, it receives the registered name and the failover event immediately.

monitor(Key, follow) keeps monitoring the registered name even if it is temporarily unregistered. The messages received are the same as for the other monitor types, but {gproc, registered, Ref, Key} is also sent when a new process registers the name.

Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140316/ad8ecbe2/attachment.htm>

More information about the erlang-questions mailing list