%% @author Rolong<[email protected]> -module(process2). -compile(export_all). -include("common.hrl"). %% Usage: %% 启动服务:process2:start(). %% 查看时间:myserver ! now. %% 结束服务:myserver ! stop. start()-> Pid = spawn(?MODULE, server, []), %% 给服务注册一个名字:myserver erlang:register(myserver, Pid). server() -> receive Msg -> ?MODULE:handle(Msg), server() end. handle(now) -> ?I("Current time is: ~p", [erlang:localtime()]); handle(stop) -> ?I("stopping ..."), exit(normal); handle(Msg) -> ?I("received undefined message:~p", [Msg]).
时间: 2024-10-14 18:48:48