[erlang-questions] Process message counter in process_info

Stanislaw Klekot erlang.org@REDACTED
Thu Sep 28 14:18:37 CEST 2017


On Thu, Sep 28, 2017 at 02:46:57PM +0300, Max Lapshin wrote:
> Looks that there is no possibility to ask process: how many messages has it
> received, no such counter.

You mean something like message_queue_len? There sure is.

#v+
1> erlang:process_info(self(), message_queue_len).
{message_queue_len,0}
2> self() ! foo.                                  
foo
3> self() ! bar.
bar
4> self() ! baz.
baz
5> erlang:process_info(self(), message_queue_len).
{message_queue_len,3}
6> receive M -> M end.
foo
7> erlang:process_info(self(), message_queue_len).
{message_queue_len,2}
#v-

-- 
Stanislaw Klekot



More information about the erlang-questions mailing list