Question

I have erlang application. I run it, it's ok, all normally. When i killed erlang shell with my application with Ctrl+C, my application stoped too, it's right behavior all ok, but how can i catch this moment? I need to clear some resources when my application stoped, normaly or with error it does not matter. I try to clean resources in gen_server:terminate, but when i killed erlang shell it didn't execute. Where can i catch moment that's my application stoped/killed?

Thank you.

Was it helpful?

Solution

When you do a ^C you are not killing the Erlang shell you are killing the whole Erlang system, the whole OS process. So after that all Erlang is dead. What is it you want to do? If you want to take down the whole system in a controlled fashion then use init:stop/0/1. It will first stop all the applications and their supervision trees allowing the behaviours to terminate properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top