作者:張華 發表於:2020-02-25
版權聲明:可以任意轉載,轉載時請務必以超鏈接形式標明文章原始出處和作者信息及本版權聲明
hello world
- erlang裏的模塊類似於類,進程則類似於類實例(相當於攜程但通過消息通訊)
- erlang變量以大寫字母開頭,以小寫字母開頭的則是符號常量,也稱爲原子(atom)
- module爲載模塊,’-module(hello). '應與文件名hello.erl同名 每行以.結束
- export向外暴露函數爲public,默認爲private, start/0中的0代表參數個數
cat << EOF | sudo tee hello.erl
%% coding: utf-8
-module(hello).
-export([start/0]).
start() ->
io:format("hello~n").
EOF
hua@t440p:/tmp$ erl
1> c(hello).
{ok,hello}
2> hello:start().
hello
ok
3> halt().
erlc hello.erl
hua@t440p:/tmp$ ls
hello.beam hello.erl
erl -noshell -s hello start -s init stop #first load hello:start(), then load hello:stop()
create erlang database - Mnesia
hua@t440p:/tmp$ erl
1> mnesia:create_schema([node()]).
ok
2> init:stop().
ok
3> hua@t440p:/tmp$ ls
hello.beam hello.erl Mnesia.nonode@nohost
OTP (Open Telecom Platform)
OTP-開放電信平臺,名字有些誤導性,因爲OTP實際要通用的多, 它是一個應用程序操作系統,包含了一組庫和實現(如一個web server, ftp server, corba orb etc),可以構建大規模,容錯和分佈式的應用程序.OTP行爲可以看作是一個用回調函數作爲參數的應用程序框架.
erlang core dump
一般說來抓dump 4種 方式:
- erlang:halt(“abort”).
- 在erlang shell下輸入CTRL C + “大寫的A”
- 等着進程崩潰自己產生dump 4, kill -SIGUSR1 (shell 無法進入時可以使用)例如已經產生了erl_crash.dump(ulimit -c unlimited設置之後運行beam出錯時就會自動產生)
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list
sudo apt update
sudo apt-cache search erlang |grep dbgsym
sudo apt install erlang-base-dbgsym -y
#source code must be the same version (erlang9.2 is using tag 20.2.2 according to 'sudo apt-get source erlang')
git clone https://github.com/erlang/otp.git
git checkout -b OTP-20.2.2
gdb /usr/lib/erlang/erts-9.2/bin/beam.smp ./core.dump -d /bak/linux/otp/erts/emulator
#https://www.erlang-solutions.com/blog/how-to-analyse-a-beam-core-dump.html