# Clarrification about "trap"

**URL:** <https://www.ruby-forum.com/t/clarrification-about-trap/159256>\
**Category:** Ruby\
**Created:** [February 2, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/clarrification-about-trap/159256 "2009-02-02T20:10:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shamika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@shamika](https://www.ruby-forum.com/u/shamika)\
**Post date:** [February 2, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/clarrification-about-trap/159256/1 "2009-02-02T20:10:37Z")

</div>

Hi,  
I know in ruby we use “trap” command to handle OS signals while passing  
the signal and the proc object as parameters respectively. when i call  
this trap function before any infinite loop it does work perfectly.  
Means it listens to the keybord signals and do as i want. But the  
problem i have is that im not clear about the way it works… In c++ we  
use separate thread to listen for signals and use another thread to run  
the program. Is the same scenario happens here with trap  
function???.. Please give me a clarification

Thanx in advance  
Shamika

---

<div class="post-metadata">

**Author:** ![shamika](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a6a055/32.png) [@shamika](https://www.ruby-forum.com/u/shamika)\
**Post date:** [February 2, 2009, 8:17pm UTC](https://www.ruby-forum.com/t/clarrification-about-trap/159256/2 "2009-02-02T20:17:36Z")

</div>

Thats how it is done:  
[http://pastie.org/377570](http://pastie.org/377570)

I’m short on an explanation right now though, better let’s wait for an  
appropriate answer.
