Process.info/1
可以讓我們看到 process 當下的詳細狀態
info = Process.info(self())
會得到相當很長超級詳細的 keyword list
[
current_function: {Process, :info, 1},
initial_call: {:proc_lib, :init_p, 5},
status: :running,
message_queue_len: 0,
links: [],
dictionary: [
{{:elixir, :eval_env},
#Macro.Env<
aliases: [],
context: nil,
context_modules: [],
file: "iex",
# ... 中略
kill: true,
size: 0
},
min_bin_vheap_size: 46422,
min_heap_size: 233,
fullsweep_after: 65535,
minor_gcs: 23
],
suspending: []
]
我們也可以使用 Process.info/2
可以只拿取需要的欄位
iex(4)> Process.info(self(), :current_function)
{:current_function, {Process, :info, 2}}
或是多個 key
iex(5)> Process.info(self(), [:current_function, :initial_call])
[current_function: {Process, :info, 2}, initial_call: {:proc_lib, :init_p, 5}]
提供了各種方面的資訊,從目前執行的函式 :current_function
, 狀態 :status
, 遞迴數 :reductions
以及監督類的 :monitors
, :parent
iex(7)> Process.info(self(), :current_function)
{:current_function, {Process, :info, 2}}
iex(8)> Process.info(self(), :status)
{:status, :running}
iex(9)> Process.info(self(), :heap_size)
{:heap_size, 6772}
iex(10)> Process.info(self(), :stack_size)
{:stack_size, 59}
iex(11)> Process.info(self(), :reductions)
{:reductions, 121195}
iex(13)> Process.info(self(), :monitors)
{:monitors, []}
iex(14)> Process.info(self(), :parent)
{:parent, #PID<0.98.0>}