Guest User

Untitled

a guest
May 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. require 'rubygems'
  2. require 'open4'
  3.  
  4. pid, stdin, stdout, stderr = Open4::popen4("ruby background.rb")
  5.  
  6. begin
  7. 10.times do |n|
  8. puts "Foreground: #{Time.now}"
  9. sleep(1)
  10. end
  11. rescue Interrupt # someone did CTRL-C
  12. end
  13.  
  14. def kill
  15. puts "Killing child"
  16. Process.kill(Signal.list['TERM'], pid)
  17. end
  18.  
  19. at_exit do
  20. kill
  21. end
Add Comment
Please, Sign In to add comment