erlang中的spawn函式

2021-07-09 02:49:32 字數 1809 閱讀 6664

spawn(fun) -> pid()

引數型別:

fun = function()    %% 引數為空的函式

返回型別:

程序pid

說明:生成乙個由fun函式啟動的、引數為空的新程序,並返回程序的pid。

spawn(node, fun) -> pid()

引數型別:

node = node()      %% 節點

fun = function()   %% 引數為空的函式

返回型別:程序pid

說明:生成乙個由在node節點上,由fun函式啟動的、引數為空的新程序,並返回程序的pid。

spawn(module, function, args) -> pid()

引數型別:

module = module()  %% 模組名

function = atom()  %% 原子函式名

args = [term()]    %% 引數列表

返回型別:程序pid

說明:生成乙個由module:function函式啟動的、引數為args列表的新程序,並返回程序的pid。

新的程序會被放入系統的排程佇列之中,延後建立。

error_handler:undefined_function(module, function, args)

is evaluated by the new process if

module:function/aritydoes not exist (where

arity

is the length of

args). the error handler can be redefined (see

process_flag/2). if

error_handler

is undefined, or the user has redefined the default

error_handler

its replacement is undefined, a failure with the reason

undef

will occur.

>spawn(speed, regulator, [high_speed, thin_cut]).

<0.13.1>

spawn(node, module, function, args) -> pid()

types:

node = node()

module = module()

function = atom()

args = [term()]

返回型別:程序pid

說明:生成乙個在node節點上,由module:function啟動的、引數為args列表的新程序,並返回程序的pid。

如果node不存在,會返回乙個沒用的pid。其他情況和spawn/3一樣。

hzhsan注:函式不等於函式的返回值。引數是表示式,如果這個表示式的結果應該是個函式,那麼就不能是函式的返回值。

Erlang 直不斷spawn新程序會有什麼現象

最近和同事聊天的時候,我突然想到程序pid格式為,其中a1代表node值,a2,a3則代表指定node下的程序值,開始a3為0。當a2的值增加到一定數後,a3的值加1,那麼問題來了 1.a2增加到多少,a3加1 2.如果a3的值也增加到這個值後會有什麼情況出現呢?原始碼 module spawn l...

如何獲得expect中spawn的命令的返回值?

我們寫乙個名為test.sh的小指令碼,程式的原始碼如下 bin bash expect test x x then echo warning no data ret 1 else echo the date is ret 0 fireturn ret expect test 我們寫乙個expect...

Erlang中的fun函式使用詳解

先看乙個erlang的規定 在eralng中,同乙個模組中的兩個函式,如果她們同名但是它們的目 arity 不同,這樣的兩個函式被認為是完全不同的兩個函式。通常情況下,這樣的函式被用作輔助函式。fun函式就是乙個匿名函式 因為他自己沒有名字 但就這個匿名函式,用處卻是很大的。fun既可以作為函式的引...