[erlang-questions] Sending a message to all linked processes

Hynek Vychodil <>
Fri May 30 14:47:30 CEST 2008


you can just write :

[ LP ! Msg || LP <- begin {links, P} = process_info(self(), links), P end ].

or without pattern match check (less reliable way):

[ LP ! Msg || LP <- element(2, process_info(self(), links)) ].

2008/5/29 John Haugeland <>:

>
> I was wondering if there is a simple and straightforward way to send a
>> message to all linked processes. Now, I am aware that a process exit signal
>> is transmitted in a functionally similar manner, so it seems that at least
>> some form of "broadcast to all linked processes" operation exists within the
>> runtime. But is it possible to invoke such functionality directly from
>> source code?
>>
>
> There may be a better way, but here's how I do it:
>
> get_linked_processes() -> [U] = [V||{links,V}<-process_info(self())], U.
>
> [ LP ! message || LP <- get_linked_processes() ].
>
> I suspect that process_info() isn't particularly cheap, so I recommend
> reconsidering the bookkeeping.
>
>   - John
>
> ---
> GuaranteedVPS.com - bandwidth commitments and root starting from $12.98/mo
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080530/2eb8491a/attachment.html>


More information about the erlang-questions mailing list