Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang Linux signal handling

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)

like image 608
jldupont Avatar asked Mar 17 '10 03:03

jldupont


People also ask

Is it possible to add a signal event handler in Erlang?

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.

How do I register a signal handler in Linux?

The signal handler can be registered with kernel using the signal () function (described above) that accepts a particular signal number and signal handler function name (though there can be other values for the second argument but we will discuss them later). Here is a working example of signal handling in Linux through the signal () function :

How do you handle signals in Linux?

Here is a working example of signal handling in Linux through the signal () function : In the program code shown above : Inside the main () function, the signal () function is used to register a handler (sig_handler ()) for SIGINT signal. The while loop simulates an infinite delay.

Can signal handler be interrupted by other signal?

Moreover, signal handler itself can be interrupted by some other signal. Each one of signals can be in one of three states: We may have our own signal handler for the signal. Signal may be handled by the default handler. Every signal has its default handler function. For instance, SIGINT default handler will terminate your application.


1 Answers

(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 :)

like image 55
Roberto Aloi Avatar answered Oct 15 '22 13:10

Roberto Aloi