# Ruby Program dont STOP

**URL:** <https://www.ruby-forum.com/t/ruby-program-dont-stop/127228>\
**Category:** Ruby\
**Created:** [January 26, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228 "2008-01-26T16:39:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/1 "2008-01-26T16:39:38Z")

</div>

Hi, I’m new in Ruby and i found a little problem, make a simple program  
with a infinite loop to print one String. I use linux (Kubuntu) and when  
i try stop the program whit CTRL+C nothing happen the program dont stop  
only when i execute the KILL command the program stop.  
I do something wrong ?? How to solve this ?

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/2 "2008-01-26T17:06:42Z")

</div>

Magician W. wrote:

> Hi, I’m new in Ruby and i found a little problem, make a simple program  
> with a infinite loop to print one String. I use linux (Kubuntu) and when  
> i try stop the program whit CTRL+C nothing happen the program dont stop  
> only when i execute the KILL command the program stop.  
> I do something wrong ?? How to solve this ?

Check on your terminal if there is any key binding for CRTL+C like “Copy  
to Clipboard”.

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/3 "2008-01-26T17:08:16Z")

</div>

Joachim G. wrote:

> Magician W. wrote:
> 
> > Hi, I’m new in Ruby and i found a little problem, make a simple program  
> > with a infinite loop to print one String. I use linux (Kubuntu) and when  
> > i try stop the program whit CTRL+C nothing happen the program dont stop  
> > only when i execute the KILL command the program stop.  
> > I do something wrong ?? How to solve this ?
> 
> Check on your terminal if there is any key binding for CRTL+C like “Copy  
> to Clipboard”.

No CTRL+C stop processes i use it in all other programs.  
Only with Ruby dont work.

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/4 "2008-01-26T17:15:02Z")

</div>

Magician W. wrote:

> No CTRL+C stop processes i use it in all other programs.  
> Only with Ruby dont work.

# cat loop.rb

while true do  
puts “test”  
sleep 1  
end

# ruby loop.rb

test  
test  
loop.rb:3:in `sleep’: Interrupt  
from loop.rb:3

One single CTRL+C works fine for me here. I’m using the XFCE terminal.

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/5 "2008-01-26T17:24:49Z")

</div>

Philipp H. wrote:

> hi,
> 
> instead of working with an infinite loop, you could trap the Crtl-C  
> signal to make your loop come to an end.
> 
> stop = false  
> trap(‘INT’) { stop = true }
> 
> until stop  
> # do your string stuff  
> end
> 
> g phil

Work perfect 😃  
Where can i find more info about the trap command ?

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/6 "2008-01-26T17:20:02Z")

</div>

hi,

instead of working with an infinite loop, you could trap the Crtl-C  
signal to make your loop come to an end.

stop = false  
trap(‘INT’) { stop = true }

until stop  
# do your string stuff  
end

g phil

---

<div class="post-metadata">

**Author:** ![magician](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a87d85/32.png) [@magician](https://www.ruby-forum.com/u/magician)\
**Post date:** [January 26, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/ruby-program-dont-stop/127228/7 "2008-01-26T17:46:56Z")

</div>

> Where can i find more info about the trap command ?

I believe with “ri”

If you dont know ri, look here  
[http://ruby.about.com/od/gettingstarted/qt/ruby\_ri.htm](http://ruby.about.com/od/gettingstarted/qt/ruby_ri.htm)
