Can messages be sent to processes interactively?

Claes Wikstrom klacke@REDACTED
Fri May 21 22:32:35 CEST 1999


> start() -> spawn(sample, server, []).
> 
> server() ->
>    receive
>       stop -> ok;
>       Msg  ->
>          io:fwrite("message received: ~w\n", [Msg]),
>          server(N)
>   end.
> 
> This compiles just fine, and I can start the process from the Erlang
> prompt with P = sample:start(), which results in a valid pid.  "P ! 1."
> from the command line, though, doesn't result in any fwrite output,
> though.  process_info(P) returns an atom of 'undefined'.
> 


One little error there, the call 

> server(N)

calls a function (called "server") with 1 (one) argument in
the local module.
Nu such function exists, thus the process will exit.

Since the process has no links to any other processes
it will silently exit, thus the 

>  process_info(P) returns an atom of 'undefined'.

So, change

>          server(N)

to

server()

and you'll be on your way

Cheers

/klacke





More information about the erlang-questions mailing list