You should look at '
ps -aux' (the '-' is deprecated on some *nix then use '
ps aux') and its output, else if '
ps' does not give all the info you need read up on the proc filesystem.
Here is some code:
#!/usr/bin/perl
use strict;
use Data::Dumper;
use constant PROG_NAME => 10;
my $what_im_looking_for = 'JVM';
my %ps_hash;
my @ps = `ps aux`;
foreach (@ps) {
my @tmp = split;
next if ($tmp[PROG_NAME] ne $what_im_looking_for);
$ps_hash{$tmp[PROG_NAME]}{cpu} += $tmp[3];
$ps_hash{$tmp[PROG_NAME]}{mem} += $tmp[4];
$ps_hash{$tmp[PROG_NAME]}{time} += $tmp[9];
}
print Dumper(\%ps_hash);
Look at the output of '
ps aux' and find what your JVM is listed as in the proc table. Then just stick the name in
$what_im_looking_for
Sample ps output:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 1324 76 ? S 2001 4:22 init [3
+]
root 2 0.0 0.0 0 0 ? SW 2001 0:07 [kflush
+d]
root 3 0.0 0.0 0 0 ? SW 2001 0:12 [kupdat
+e]
root 4 0.0 0.0 0 0 ? SW 2001 0:00 [kpiod]
root 5 0.0 0.0 0 0 ? SW 2001 0:25 [kswapd
+]
root 6 0.0 0.0 0 0 ? SW< 2001 0:00 [mdreco
+veryd]
root 45 0.0 0.0 0 0 ? SW 2001 0:00 [khubd]
root 353 0.0 0.5 1384 340 ? S 2001 0:26 syslogd
+ -m 0
root 363 0.0 0.2 1680 184 ? S 2001 0:01 klogd
^^^^^^^
+^^^^^^^
This is
+ where the name is
grep
grep> cd pub
grep> more beer
|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.