S
sanjayayogi
#!/usr/bin/ruby -w
# kill_pid.rb - kill a process by a given name
# Written by (e-mail address removed)
# This code first asks you the name of the process you want to kill -
respond with the name of the process
# It will return the pid - if you you only want the pid comment out
the final line:
# ie: #exec killall_pid
def getBinding(str)
return binding
end
puts " Hello, what PID do you want? "
process = gets.chomp
a = process
# puts a
b = "'ps -C " + a + " -o pid='"
# puts b
D = "IO.popen(" + b + ", 'r+') do |pipe|"
str = D + "\n" + "pipe.close_write" + "\n" + "puts pipe.read" + "\n" +
"end"
#put str
def pid
x = D + "\n" + "pipe.close_write" + "\n" + "puts pipe.read" + "\n" +
"end"
end
kill = "kill -9 "
eval pid
# killall -i makes the code interactive
killall_pid = "killall -i " + a
puts killall_pid
# kills the process by name - not pid (does not seem to work with all
processes - I think
# it would be better written to kill the process by pid instead but I
do not know how to
# take the out put of eval pid and use the kill -9 command with the
pid IDEAS ANYONE?
exec killall_pid
# kill_pid.rb - kill a process by a given name
# Written by (e-mail address removed)
# This code first asks you the name of the process you want to kill -
respond with the name of the process
# It will return the pid - if you you only want the pid comment out
the final line:
# ie: #exec killall_pid
def getBinding(str)
return binding
end
puts " Hello, what PID do you want? "
process = gets.chomp
a = process
# puts a
b = "'ps -C " + a + " -o pid='"
# puts b
D = "IO.popen(" + b + ", 'r+') do |pipe|"
str = D + "\n" + "pipe.close_write" + "\n" + "puts pipe.read" + "\n" +
"end"
#put str
def pid
x = D + "\n" + "pipe.close_write" + "\n" + "puts pipe.read" + "\n" +
"end"
end
kill = "kill -9 "
eval pid
# killall -i makes the code interactive
killall_pid = "killall -i " + a
puts killall_pid
# kills the process by name - not pid (does not seem to work with all
processes - I think
# it would be better written to kill the process by pid instead but I
do not know how to
# take the out put of eval pid and use the kill -9 command with the
pid IDEAS ANYONE?
exec killall_pid