erlang一些脚本

通过supervisor terminate进程


Fun = fun({,Pid,,_}) -> supervisor:terminate_child(player_sup,Pid) end.
lists:map(Fun,supervisor:which_children(player_sup)).

检测解散的工会


Fun1 = fun({Name,Pid,,}) -> IsLive = (Pid == undefined)end.
lists:filter(Fun1,supervisor:which_children(guild_sup)).

检测活着的工会数量


Fun2 = fun({Name,Pid,,},Sum) -> IsPid = is_pid(Pid),if IsPid -> IsAlive = is_process_alive(Pid),if IsAlive -> Sum + 1;true -> Sum end;true -> Sum end end.
lists:foldl(Fun2,0,supervisor:which_children(guild_sup)).

你可能感兴趣的:(erlang一些脚本)