Skip to content

Instantly share code, notes, and snippets.

@K-atc
Created May 17, 2015 14:46
Show Gist options
  • Select an option

  • Save K-atc/11640416dcf616fa501a to your computer and use it in GitHub Desktop.

Select an option

Save K-atc/11640416dcf616fa501a to your computer and use it in GitHub Desktop.
特定のタスクをバックグラウンド実行し、好きなタイミングで終了するRubyスクリプト
# coding: utf-8
# $ cat ./hoge.sh
# #!/bin/bash
# while true; do
# date; sleep 1
# done
cmd = "sh ./hoge.sh"
pid = Process.spawn cmd, STDOUT=>STDOUT
puts "current process: #{pid}"
sleep 5
puts "Kill Process!"
Process.kill 9, pid.to_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment