gen_server:format_status/2 only works with registered processes

Vance Shipley vances@REDACTED
Thu Mar 20 22:36:04 CET 2003


Background

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.

Problem

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.

	-Vance


$ erl
Erlang (BEAM) emulator version 5.2.3.3 [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",[]}]},
 {data,[{"State",
         {state,"/usr/local/lib/erlang",
                [".",
                 "/usr/local/lib/erlang/lib/kernel-2.8.1.1/ebin",
                 "/usr/local/lib/erlang/lib/stdlib-1.11.4.1/ebin",
                 "/usr/local/lib/erlang/lib/webtool-0.7.1/ebin",
                 "/usr/local/lib/erlang/lib/tv-2.0.4/ebin",
                 "/usr/local/lib/erlang/lib/tools-2.2/ebin",
                 "/usr/local/lib/erlang/lib/toolbar-1.1.0/ebin",
                 "/usr/local/lib/erlang/lib/ssl-2.3.5/ebin",
                 "/usr/local/lib/erlang/lib/snmp-3.3.8/ebin",
                 "/usr/local/lib/erlang/lib/sasl-1.9.4/ebin",
                 "/usr/local/lib/erlang/lib/runtime_tools-1.3/ebin",
                 "/usr/local/lib/erlang/lib/pman-2.4.1/ebin",
                 "/usr/local/lib/erlang/lib/parsetools-1.2/ebin",
                 "/usr/local/lib/erlang/lib/os_mon-1.6.0.2/ebin",
                 "/usr/local/lib/erlang/lib/orber-3.4/ebin",
                 "/usr/local/lib/erlang/lib/observer-0.9.3/ebin",
                 "/usr/local/lib/erlang/lib/mnesia_session-1.1.5/ebin"|...],
                9,
                10,
                interactive}}]}]
3> f(StatusData).
ok
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>]},
                             {lists,flatmap,2},
                             {gen_server,format_status,2},
                             {erl_eval,expr,3},
                             {erl_eval,exprs,4},
                             {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