首页 > 其他 > 详细

erlang中查找占用内存最多的进程

时间:2014-08-19 16:54:25      阅读:365      评论:0      收藏:0      [点我收藏+]

     在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).


本文出自 “莫小鹏” 博客,请务必保留此出处http://moxiaopeng.blog.51cto.com/3763412/1542033

erlang中查找占用内存最多的进程,布布扣,bubuko.com

erlang中查找占用内存最多的进程

原文:http://moxiaopeng.blog.51cto.com/3763412/1542033

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!