このプロセスに関連付けるために、多くのスレッドがリンクを作成するプロセスがあります。このようにシステムを作成したので、アプリケーション自体の内部のリストを追跡しなくても、いつでも誰が中央プロセスに関連付けられているかを簡単に確認できます。私は簡単に行うことができprocess_info(self(),links)
、erlangはどのプロセスがまだ生きているかどうかなどを追跡します。
少なくとも、このスレッドで返されるリストが現時点では正確ではないことがわかるまで、私はそう思っていました。
% P is my central pid
(node@host)212> P.
<0.803.0>
% Get all the links to it
(node@host)213> {links,L} = process_info(P,links).
{links,[<0.29179.155>,<0.6492.250>,<0.29990.293>|...]}
% Counting out all the links
(node@host)214> length(L).
31154
% Filtering out all of the dead processes, put them in Lf
(node@host)215> Lf = lists:filter(fun(Pid) -> try process_info(Pid,links) of {links,_} -> true; _ -> false catch _:_ -> false end end, L).
[<0.29179.155>,<0.6492.250>,<0.29990.293>,<0.23619.530>|...]
% Lf is only about half the size, half the linked processes are dead!
(node@host)216> length(Lf).
15654
% Proof that the links haven't changed in the interim
(node@host)217> {links,L} = process_info(P,links).
{links,[<0.29179.155>,<0.6492.250>,<0.29990.293>|...]}
リンクの一部は別のマシンのノード上のスレッドからのものである可能性があるため、これを引き起こすと私が考えることができる唯一のことは、ネットワーク接続の問題です。それはこれについての可能な説明ですか?そして、スレッドにリンクリストをクリーンアップさせる方法はありますか?