zentara has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fork and exec a codeblock
by Aristotle (Chancellor) on Mar 16, 2004 at 19:32 UTC | |
by Anomynous Monk (Scribe) on Mar 16, 2004 at 19:38 UTC | |
by Aristotle (Chancellor) on Mar 16, 2004 at 19:45 UTC | |
|
Re: fork and exec a codeblock
by zentara (Cardinal) on Mar 17, 2004 at 15:57 UTC |