Erlang Linux signal handling

前端 未结 2 703
你的背包
你的背包 2021-02-05 12:12

Is it possible to trap Linux signals (e.g. SIGUSR1) through an handler in Erlang? (without having to resort to a driver crafted in C)

2条回答
  •  春和景丽
    2021-02-05 12:29

    This is possible since Erlang/OTP 20.0, released in June 2017. It was done through this pull request that adds an event manager for signals called erl_signal_server. See the "OS Signal Event Handler" section in the kernel manual page.

    If you're interested in SIGUSR1, note that the default handler will make the Erlang VM halt and produce a crash dump. To avoid that, it's not enough to add your own handler to erl_signal_server; you have to swap the default handler for it:

    gen_event:swap_handler(erl_signal_server, {erl_signal_handler, []}, {foo, []}).
    

提交回复
热议问题