in reply to Re: Calculating percent cpu in linux?
in thread Calculating percent cpu in linux?
But what I really wanted to say, is I often use a similar script I wrote called MeM. It pops up a Tk window in the upper left corner of the screen, and constantly updates and reports memory usage of a pid( or the calling script). Anyways, you could easily modify the code, to report cpu usage. Here is the code, just change it to run your code, and name it accordingly.
package MeM; 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 =$$; if (fork() == 0) { require Tk; my $mw = new MainWindow; $mw->overrideredirect(1); my $t = $mw->Label(-text => '', -bg => 'black', -fg => 'yellow')-> +pack; $0 = 'MeM'; my $id = Tk::After->new($mw, 1000, 'repeat', [ \&refresh, $pid ]); Tk::MainLoop(); 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; $t->configure(-text => "PID: $pid -> $size"); if ($size eq '') { exit } } } 1;
|
|---|