# Detect when a Ruby program exits

**URL:** <https://www.ruby-forum.com/t/detect-when-a-ruby-program-exits/157320>\
**Category:** Ruby\
**Created:** [January 9, 2009, 11:28am UTC](https://www.ruby-forum.com/t/detect-when-a-ruby-program-exits/157320 "2009-01-09T11:28:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [January 9, 2009, 11:28am UTC](https://www.ruby-forum.com/t/detect-when-a-ruby-program-exits/157320/1 "2009-01-09T11:28:58Z")

</div>

Hi all,

Is there a way to have your code notified when a Ruby process is  
terminated?  
I’m looking for a way to serialize a bunch of in-memory data to disk  
automatically when a Rails app is shut down. I might be better off  
storing  
it in SQLite but would like to know if the in-memory option is possible  
first.

Thanks,  
James

> **[jcoglan - Overview](https://github.com/jcoglan)**
>
> jcoglan has 140 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [January 9, 2009, 11:37am UTC](https://www.ruby-forum.com/t/detect-when-a-ruby-program-exits/157320/2 "2009-01-09T11:37:53Z")

</div>

Your are probably looking for Kernel::at\_exit

blambeau

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [January 9, 2009, 11:50am UTC](https://www.ruby-forum.com/t/detect-when-a-ruby-program-exits/157320/3 "2009-01-09T11:50:15Z")

</div>

2009/1/9 LAMBEAU Bernard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Your are probably looking for Kernel::at\_exit

Fantastic, just what I needed. Thanks!
