problems spawing processes

Bengt Kleberg bengt.kleberg@REDACTED
Tue Jan 25 16:26:09 CET 2005


Dietmar Schaefer wrote:
> Hi !

...deleted
> -export([startComm/2, getMessages/1, sendMessages/1]).
> 
> 
> startComm(ListenPort,SendPort) ->
>     io:format("sendport = ~p~n",  [SendPort]),
>      io:format("listenport = ~p~n",[ListenPort]),
>     
>     register (getProc,spawn(?MODULE, getMessages,   [ListenPort])),
>     register (sendProc,spawn(?MODULE, sendMessages,  [SendPort])),
> %%    process_flag(trap_exit, true),                    %% get informed
> when server failed
> 
>     io:format("Hello world~n").

try to use erlang:spawn_link/1 instead of erlang:spawn/3. ie do

erlang:register( get_proc, erlang:spawn_link( fun() -> 
get_messages(Listen_port) end ) ),

the link makes it possible to get a trace of errors in the new process. 
and using the fun() makes it possible not to export get_messages/1.


> where
> 
> %% @doc
> %%    gets messages from 4DP (mainly AuS)
> %%    messages are received as lists of strings
> %%
> getMessages(Port) when integer(Port) ->
>     io:format("get messages from port ~p~n",Port),

io:format/2 should have a list as its second argument:
io:format("get messages from port ~p~n", [Port]),

running with a spawn_link/1 i get:

** exited: {badarg,[{io,format,[<0.21.0>,"get messages from port 
~p~n",1234]},
                     {comm,get_messages,1}]} **


bengt



More information about the erlang-questions mailing list