SIGTERM CATS IN ERLANG

Trust that you are doing well.

I need to catch SIGTERM while running erlang so that I can save the state of the ets in the dets file and when the system comes back again to start from where it stopped. I could write a C program to catch the SIGTERM, but the VM will catch the same signal as well. Now, how would I ask ERLANG IGNORE SIGTERM so that only my C program catches the signal and passes it to erlang so that it can save the state before exiting.

+3


source to share


1 answer


Easy solution: don't send SIGTERM to any Erlang VM processes. Send it only to the C program and ask it to listen for a signal for your Erlang programs that it knows how to talk to. The traditional way is to have the C program write down its PID at startup and write a shell command that read the "PID" of process C somewhere. The shutdown shell command doesn't need to know anything about VM Erlang.

There are better ways to handle this. Why are you expecting SIGTERM? If you are using a persistent service on a * nix system, you should have startup and shutdown scripts that work with the system. They can send "clean shutdown" commands to your Erlang service in any way you want to write them (for example, they can be script calls themselves).



If you are trying to prevent data loss when the OS crashes, this is not the right way to do it. There are other trade-offs (like the overhead of working from a disk or external storage), as deleting to disk in the middle of an OS crash is more likely to corrupt or destroy all of your data than keeping the very last bits of it.

+1


source







All Articles