Skip to content

Instantly share code, notes, and snippets.

@kingluo
Last active July 7, 2023 08:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingluo/6e5245692b76dda5ecd4 to your computer and use it in GitHub Desktop.
Save kingluo/6e5245692b76dda5ecd4 to your computer and use it in GitHub Desktop.
erlang noshell
$ erlc processes.erl
$ erl -noshell -s processes test -s init stop
the max processes is 262144
the proecess time is 2.0:3.57
$ erl -noshell -s processes test2 100000 -s init stop
the max processes is 262144
{"init terminating in do_boot",{system_limit,[{erlang,spawn,[erlang,apply,[#Fun<processes.2.26012808>,[]]],[]},{erlang,spawn,1,[]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,max,1,[{file,"processes.erl"},{line,10}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
# program freeze here...
# Ctrl+C not work
# Instead, press Ctrl+Z, then pkill -9 beam.smp
-module(processes).
-compile(export_all).
%%-export(export_all).
max(N)->
Max=erlang:system_info(process_limit),
io:format("the max processes is ~p ~n",[Max]),
statistics(runtime),
statistics(wall_clock),
L=for(1,N,fun()->spawn(fun()->wait() end) end),
{_,Time1}=statistics(runtime),
{_,Time2}=statistics(wall_clock),
lists:foreach(fun(Pid)->Pid!die end,L),
U1=Time1*1000/N,
U2=Time2*1000/N,
io:format("the proecess time is ~p:~p ~n",[U1,U2]).
wait()->
receive
die->void
end.
for(N,N,F)->[F()];
for(I,N,F)->[F()|for(I+1,N,F)].
test()->
max(100000).
test2(N)->
max(N).
main([])->
max(100000).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment