在erlang查看占用内存最多的进程,可以用etop,在终端输入下面语句:

spawn(fun() -> etop:start([{output, text}, {interval, 1}, {lines, 20}, {sort, memory}]) end).

     但etop有时会启动不起来,循环是系统比较繁忙的时候,这时可以用下面的方法:

%%查找最大内存的进程
find_max_memory_process() ->
    %%进程列表
    ProcessL = processes() -- [self()],
    %%获取进程信息,
    AttrName = memory,
    F = fun(Pid, L) ->  
                case process_info(Pid, [AttrName, registered_name, current_function, initial_call]) of
                    [Attr, Name, Init, Cur] ->
                        Info = {Attr, [{pid, Pid}, Name, Init, Cur]},
                        [Info | L]; 
                    undefined ->
                        L   
                end 
        end,
    ProInfoL = lists:foldl(F, [], ProcessL),
    %%排序
    CompF = fun({A, _},{B, _}) ->  
                    A > B 
            end,
    ProInfoSortL = lists:usort(CompF, ProInfoL),
    %%取前10个
    Num = 10, 
    lists:sublist(ProInfoSortL, Num).