gen_server:format_status/2 only works with registered processes

Vance Shipley <>
Thu Mar 20 22:36:04 CET 2003


Both gen_server.erl and gen_fsm.erl have a (undocumented) function 
which is used to pretty print the persistent data they keep.  The
way it works is that you first call sys:get_status/1 (documented)
to retrieve the process's status and then format the state data
in a contextually relevant way with gen_[server|fsm]:format_status/2.
The nice thing is that gen_[server|fsm]:format_status/2 will check
to see if the user's callback module has exported a format_status/2
and if so it will call that function to get an even more contextually
relevant way to present the data.  I find this all very handy.


Now the problem is that, at least in R9B-[0|1], this only works if the
process is registered!  In the following example I am peeking at a 
couple gen_server processes the system runs.  I am referring to each
by PID but the process which is not registerd fails.


$ erl
Erlang (BEAM) emulator version [source] [hipe] [threads:0]

Eshell V5.2.3.3  (abort with ^G)
1> i().
Pid                   Initial Call                          Heap     Reds Msgs
Registered            Current Function                     Stack              
<0.17.0>              code_server:init/1                     377    46225    0
code_server           gen_server:loop/6                       12              
<0.23.0>              kernel_config:init/1                   233       45    0
                      gen_server:loop/6                       12              

2> {_,_,_,StatusData} = sys:get_status(list_to_pid("<0.17.0>")),
2> gen_server:format_status([], StatusData).
[{header,"Status for generic server code_server"},
 {data,[{"Status",running},{"Parent",<0.9.0>},{"Logged events",[]}]},
3> f(StatusData).
4> {_,_,_,StatusData} = sys:get_status(list_to_pid("<0.23.0>")),
4> gen_server:format_status([], StatusData).
** exited: {function_clause,[{lists,thing_to_list,[<0.23.0>]},
                             {shell,eval_loop,2}]} **

=ERROR REPORT==== 20-Mar-2003::16:31:37 ===
Error in process <0.25.0> with exit value: {function_clause,[{lists,thing_to_list,[<0.23.0>]},{lists,flatmap,2},{gen_server,format_status,2},{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}

More information about the erlang-questions mailing list