码迷,mamicode.com
首页 > 系统相关 > 详细

Erlang入门:进程实例操作与练习2

时间:2015-01-11 11:02:05      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:erlang   面试题   入门教程   实例   

%% @author Rolong<rolong@vip.qq.com>

-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]).

Erlang入门:进程实例操作与练习2

标签:erlang   面试题   入门教程   实例   

原文地址:http://blog.csdn.net/zhongruixian/article/details/42607939

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!