Erlang Linux signal handling

风流意气都作罢 提交于 2019-12-03 12:20:04

问题


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)


回答1:


(NOT A REAL ANSWER)

In 2001 someone asked:

Does anyone have any examples of unix signal handling in erlang. I would like to make a loadbalancer that I have written respond to sighup.

At that time the answer was:

There is no provision for handling signals in Erlang "itself", i.e. you will need to use a driver - or a port program of course, might actually be a better idea. Also for the driver case, the emulator has its own handler for a number of signals, and interfering with that will probably have "interesting" results - but SIGHUP should be OK I believe.

SOURCE: http://www.erlang.org/pipermail/erlang-questions/2001-October/003752.html

As far as I know, nothing changed since then. But this is extremely interesting. If anyone has any news about this, please let us know :)




回答2:


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, []}).


来源:https://stackoverflow.com/questions/2459672/erlang-linux-signal-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!