[erlang-questions] erlang:monitor() lag time: how long to expect?

Per Hedeland per@REDACTED
Wed May 21 23:38:37 CEST 2008


"Igor Ribeiro Sucupira" <igorrs@REDACTED> wrote:
>
>I don't know the reason for the delay, but you shouldn't be trying to
>monitor something that does not exist.

Maybe you "shouldn't be trying", but it *must* be OK to do that,
otherwise monitor() would be near useless - you would always have to
(somehow) check that the process still existed after calling monitor().

1> register(foo, spawn(fun() -> timer:sleep(100) end)).
true
2> erlang:monitor(process, foo).   % took more than 100 ms to type:-)
#Ref<0.0.0.44>
3> flush().
Shell got {'DOWN',#Ref<0.0.0.44>,process,{foo,nonode@REDACTED},noproc}
ok

(Yes, you could use spawn_monitor() in the particular case that you are
spawning the process, but not in general.)

>>From the man pages:
>"When a process is monitored by registered name, the process that has
>the registered name at the time when erlang:monitor/2 is called will
>be monitored. The monitor will not be effected, if the registered name
>is unregistered."

Uh, I believe that just says that the monitoring continues even if the
name is unregistered - has no bearing on what happens when you try to
monitor something that doesn't exist in the first place. The relevant
part is in the next paragraph:

   A  'DOWN'  message will be sent to the monitoring process if Item dies,
   if Item does not exist, or if the connection is lost to the node  which
   ^^^^^^^^^^^^^^^^^^^^^^
   Item resides on. A 'DOWN' message has the following pattern:
   [snip]

I don't know the reason for Scott's delay either though...

--Per Hedeland




More information about the erlang-questions mailing list