0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ErlangAdvent Calendar 2016

Day 22

Erlangで浮いたプロセスを調べる方法

Posted at
% erl
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V8.1  (abort with ^G)

%% 1) まずプロセス数を調べる
1> Before = processes().
2> length(Before).
26

%% 2) 次に調べたい処理をする(通常はもっと複雑な処理)
3> Loop = fun(F) -> timer:sleep(100), F(F) end.
4> LeakPid = spawn(fun() -> Loop(Loop) end).
<0.62.0>

%% 3) もう一度プロセス数を調べる
5> After = processes().
6> length(After).
27

%% 4) 2回調べたプロセス数の差分を取る
7> Delta = After -- Before.
[<0.62.0>]

%% 5) 詳細を見る
8> [{Pid, erlang:process_info(Pid)} || Pid <- Delta].
[{<0.62.0>,
  [{current_function,{timer,sleep,1}},
   {initial_call,{erlang,apply,2}},
   {status,waiting},
   {message_queue_len,0},
   {messages,[]},
   {links,[]},
   {dictionary,[]},
   {trap_exit,false},
   {error_handler,error_handler},
   {priority,normal},
   {group_leader,<0.50.0>},
   {total_heap_size,1363},
   {heap_size,987},
   {stack_size,10},
   {reductions,6574},
   {garbage_collection,[{max_heap_size,#{error_logger => true,
                                         kill => true,
                                         size => 0}},
                        {min_bin_vheap_size,46422},
                        {min_heap_size,233},
                        {fullsweep_after,65535},
                        {minor_gcs,20}]},
   {suspending,[]}]}]                     
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?