[erlang-questions] process_info message_queue_len

Hans Bolinder hans.bolinder@REDACTED
Fri Jun 1 16:23:44 CEST 2007

[Heinrich Venter:]
> I want to know which of the processes in my system is taking long to handle
> messages.  I tried to use erlang:process_info(PID) to get the
> message_queue_len.  The problem is that it always returns 0.
> As an example, I built the following function to test it.
> F=fun() -> receive xx -> io:format("done~n") end end.
> P=spawn(F).
> P!abc
> erlang:process_info(P).
> This gives me a message_queue_len of 0.  Am I missing something?

The example works fine if the code is compiled, but in the Erlang
shell it does not give the expected result.

This is due to the way the shell (or rather: erl_eval) evaluates
'receive': the messages are removed from the message queue and kept in
a list until some receive clause matches.

Best regards

Hans Bolinder, Erlang/OTP team

More information about the erlang-questions mailing list