package GMeM; use warnings; use strict; #save this file as GMeM.pm and place in your PERL5LIB my $pid =$$; #gets the caller script's pid and #passes it thru the fork-&-exec below #only gets created after fork and exec to prevent #module's X socket connection from interfering with #calling program's X socket connection if ((defined $ARGV[0]) and ($ARGV[0] eq 'GMeM')) { #use Gtk2 '-init'; #BAD unnecessarily loads modules eval "use Gtk2 -init;"; $pid = $ARGV[1]; my $blueh = Gtk2::Gdk::Color->new (0,0xFFFF,0xFFFF); my $bluel = Gtk2::Gdk::Color->new (0,0xCCCC,0xFFFF); Gtk2::Rc->parse_string(<<___EOS); style "normal" { font_name ="Sans Bold 12" } widget "*" style "normal" ___EOS my $win = Gtk2::Window->new('popup'); $win->signal_connect( 'destroy' => \&delete_event ); my ($xscr, $yscr) = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height); $win->move($xscr - 180, $yscr - 20); my $but = Gtk2::Button->new("PID: $pid-> " ); $but->modify_bg ('normal', $blueh); $but->modify_bg ('prelight', $bluel); $but->signal_connect( 'clicked' => \&delete_event ); $win->add($but); $0 = "GMeM $pid"; $win->show_all(); &refresh($pid); my $repeater = Glib::Timeout->add(1000, sub{ refresh($pid) ; 1;} ); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return 0; } sub refresh { my $pid = shift; #asmutils version of cat #my @size = split "\n", `/home/zentara/perl5lib/cat /proc/$pid/status`; my @size = split "\n", `cat /proc/$pid/status`; (my $vmsize) = grep { /VmSize/ } @size; my (undef, $size) = split ' ', $vmsize; $but->set_label("PID: $pid -> $size"); if ($size eq '') { exit } } #################################### } elsif (fork() == 0) { exec "$^X -MGMeM -e1 GMeM $pid"; } # thanks to muppet for this cleverness 1;