summaryrefslogtreecommitdiff
path: root/code/snippets/trap_int_signal.rb
diff options
context:
space:
mode:
Diffstat (limited to 'code/snippets/trap_int_signal.rb')
-rw-r--r--code/snippets/trap_int_signal.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/code/snippets/trap_int_signal.rb b/code/snippets/trap_int_signal.rb
new file mode 100644
index 0000000..b1d9d5b
--- /dev/null
+++ b/code/snippets/trap_int_signal.rb
@@ -0,0 +1,8 @@
+trap(:INT) { puts 'This is the first signal handler' }
+
+old_handler = trap(:INT) {
+ old_handler.call
+ puts 'This is the second handler'
+ exit
+}
+sleep 5 # so that we have time to send it a signal