Veerasundaravel's Ruby on Rails Weblog

January 28, 2013

Kill a program using Ruby

Filed under: Ruby, Ruby On Rails — Veerasundaravel @ 12:54 pm

Old school but helpful.

Get process id of a running program and kill it if you need.

pid = `pgrep -f “ruby running_program.rb”`.split(“\n”).first.to_i
`kill -9 #{pid}`

Specify your program or script name inside the double quotes instead of ruby running_program.rb. It will return the pid of the program and you can get it in the variable pid. In next line you can see the kill command in order to kill the program.

%d bloggers like this: