summaryrefslogtreecommitdiff
path: root/ruby/timeout.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-14 16:46:27 +0200
committerPatrick Simianer <p@simianer.de>2014-06-14 16:46:27 +0200
commit26c490f404731d053a6205719b6246502c07b449 (patch)
tree3aa721098f1251dfbf2249ecd2736434c13b1d48 /ruby/timeout.rb
init
Diffstat (limited to 'ruby/timeout.rb')
-rwxr-xr-xruby/timeout.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/ruby/timeout.rb b/ruby/timeout.rb
new file mode 100755
index 0000000..f5c1e7e
--- /dev/null
+++ b/ruby/timeout.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+require 'timeout'
+
+
+puts 'starting process'
+pid = Process.spawn('sleep 20')
+begin
+ Timeout.timeout(5) do
+ puts 'waiting for the process to end'
+ Process.wait(pid)
+ puts 'process finished in time'
+ end
+rescue Timeout::Error
+ puts 'process not finished in time, killing it'
+ Process.kill('TERM', pid)
+end
+