What problem could I have with this powerful computer, simple, flash (and some movies problems, but the codecs are not supported to 64 bits yet).
So I decided to make this simple, I first made a script called kill_flash:
#!/bin/bash
PID=`ps -ef|grep -i chrome|grep -i adobe|perl -lane 'print $F[1];'`
echo "pid: $PID"
kill -9 $PID
echo "RC: $?"
That was quite useful, but as when I see flash things, I'm using mostly just a browser, and was quite annoying to go to the console and type kill_flash. So I made my first ruby + gtk2 app (is short, but useful to me):
#!/usr/bin/env ruby
require 'rubygems'
require 'sys/proctable'
include Sys
require 'gtk2'
$ToKill = Array.new()
def do_kill_flash
$ToKill.each{|mpid|
Process.kill("KILL",mpid)
}
end
window = Gtk::Window.new
window.signal_connect("delete_event") {
puts "delete event occurred"
#true
false
}
window.signal_connect("destroy") {
puts "destroy event occurred"
Gtk.main_quit
}
buttonKillFlash = Gtk::Button.new("Kill Flash")
buttonKillFlash.signal_connect("clicked") {
msg = "Kill the following: \n"
ProcTable.ps{|ps|
if ps.cmdline =~ /flashplugin-nonfree\/libflashplayer/
msg = msg.to_s + ps.cmdline
$ToKill.push(ps.pid.to_i)
end
}
msg = msg.to_s + "?"
unless $ToKill.empty?
dialog = Gtk::MessageDialog.new(window,
Gtk::Dialog::DESTROY_WITH_PARENT,
Gtk::MessageDialog::QUESTION,
Gtk::MessageDialog::BUTTONS_OK_CANCEL,
msg)
dialog.run do |response|
case response
when Gtk::Dialog::RESPONSE_OK
do_kill_flash
end
end
else
dialog = Gtk::MessageDialog.new(window,
Gtk::Dialog::DESTROY_WITH_PARENT,
Gtk::MessageDialog::QUESTION,
Gtk::MessageDialog::BUTTONS_OK,
"Nothing to kill")
dialog.run
end
dialog.destroy
}
button_exit = Gtk::Button.new("close")
button_exit.signal_connect("clicked"){
Gtk.main_quit
}
box = Gtk::VBox.new(false,0)
box.pack_start(buttonKillFlash,true,false,2)
box.pack_start(button_exit,true,false,2)
window.border_width = 10
window.add(box)
window.show_all
Gtk.main
As you could see, this code is dirty and quick. In the future, I'll put some other buttons to make other things (like make a class to the do_kill_flash), but for now, is useful to me.
Making a gnome applet was quite difficult, and I should write more code, just to make the kill, but when I read more on that, I'll put the code here.
No hay comentarios.:
Publicar un comentario