package MeM; use warnings; use strict; use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); # inherit the import() from Exporter.pm @EXPORT_OK = qw(init); # list of things to export if asked to my $pid = $$; if(fork() == 0){exec '/home/zentara/perl5lib/memmonitor',$pid } 1;
That's working good, but requires the script to be a separate file. So after alot of hacking( and failures), I finally got the following to work. But is it any good? I had to use the weird perl shebang because exec wanted shell syntax.
package MeMz; use warnings; use strict; use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); # inherit the import() from Exporter.pm @EXPORT_OK = qw(); # list of things to export if asked to ################################################# my $pid = $$; my $perl=<<'EOP'; eval 'exec perl -S $0 "$@"' if 0; use Tk; my $mw = new MainWindow; $mw->overrideredirect(1); my $t = $mw->Label(-text=>'', -bg=>'black', -fg=>'yellow')->pack; my $id = Tk::After->new($mw,1000,'repeat',[\&refresh,$pid]); MainLoop; sub refresh{ my $pid = shift; my @size = split "\n", `cat /proc/$pid/status`; (my $vmsize) = grep {/VmSize/} @size; my (undef,$size) = split ' ',$vmsize; $t->configure(-text=>"PID: $pid -> $size"); if($size eq ''){Tk::exit} } EOP if(fork() == 0){ exec (eval $perl ) } 1;
In reply to fork and exec a codeblock by zentara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |