Catch when destroying erlang app

I have an erlang application. I run it, everything is fine, everything is fine. When I killed the erlang wrapper with my app with Ctrl+C

, my app stopped too, the correct behavior is ok, but how can I catch this moment? I need to clean up some resources when my application stopped, normal or error, it doesn't matter. I am trying to clean up resources in gen_server:terminate

but when I killed the erlang shell it was not executing. Where can I catch the moment when my application has stopped / killed?

Thank.

+3


source to share


1 answer


When you do ^C

, you are not killing the Erlang shell, you are killing the entire Erlang system, the entire OS process. So after that all Erlang is dead. What do you want to do? If you want to manage the entire system in a controlled manner, use init:stop/0/1

. It will first stop all applications and watch trees allowing the behavior to terminate correctly.



+3


source







All Articles