J
Jun Young Kim
Hi, folks.
first )
I have a question to get a process id by using it's name for all
platforms.
second)
If I want to kill some processes by it's name, are there efficient way
to do it for all platform?
For a solution for this problem, I am now using the following way
ex)
lines = $x{ ps -Au${ENV['USER']} }.split("\r?\n")
lines.each do |line|
if line.match(process_name)
pids << line.strip.split[0]
end
end
count = 0
pids.each do |pid|
%x{ kill #{pid} }
count += 1 if $?.existstatus.zero?
end
print "total terminated processes : %d" % count
but, this way depends on only unix platforms.
moreover, I am not sure that all platform's output of "ps -Au" are same.
first )
I have a question to get a process id by using it's name for all
platforms.
second)
If I want to kill some processes by it's name, are there efficient way
to do it for all platform?
For a solution for this problem, I am now using the following way
ex)
lines = $x{ ps -Au${ENV['USER']} }.split("\r?\n")
lines.each do |line|
if line.match(process_name)
pids << line.strip.split[0]
end
end
count = 0
pids.each do |pid|
%x{ kill #{pid} }
count += 1 if $?.existstatus.zero?
end
print "total terminated processes : %d" % count
but, this way depends on only unix platforms.
moreover, I am not sure that all platform's output of "ps -Au" are same.