I'm trying to write a script to monitor memory. I was
able to get inside the proc directory, and decode some
of the process information. I know I could use ps, vmstat,
etc, but I've had problems where /usr/ucb/ps -auxww
locks up on some of our servers. I'm trying to have a one
script fits all.
Anyway, the biggest problem is, I'd like to verify processes
by there COMPLETE process name. ps, vmstat, etc cuts
off most of the process name / command line arguments.
I believe I found in Solaris where this type of information
is stored. But I'm not sure if I can get to it from perl.
foreach $pid (sort {$a<=>$b} <*>)
{
$uid = getpwuid((lstat "/proc/$pid")[4]);
next if $pid == $$;
next if $uid ne "netpoint";
open(PSINFO, "/proc/$pid/psinfo") || next;
read(PSINFO, $psinfo,256);
close PSINFO;
my
(
$pr_flag, $pr_nlwp, $pr_pid, $pr_ppid,
$pr_pgid, $pr_sid, $pr_uid, $pr_euid,
$pr_gid, $pr_egid, $pr_addr, $pr_size,
$pr_rssize, $pr_pad1, $pr_ttydev, $pr_pctcpu,
$pr_pctmem, $pr_start, $pr_time, $pr_ctime,
$pr_fname, $pr_psargs, $pr_wstat, $pr_argc,
$pr_argv, $pr_envp, $pr_dmodel, $pr_taskid,
$pr_projid, $pr_nzomb, $pr_poolid, $pr_zoneid,
$filler
) = unpack("iiiiiiiiiiIiiiiSSa8a8a8Z16Z80iiIIaa3iiiiii", $psinfo);
print "\n\n---------------\n\nUser: " . $uid;
print "\nPID: " . $pid;
print "\nMemory: " . ($pr_pctmem / 0x8000 ) * 100;
print "\nCPU: " . ($pr_pctcpu / 0x8000 ) * 100;
print "\nArguments: " . $pr_envp[1];
}
$pr_envp and $pr_argv hold memory addresses of the command line. Is it possible memory addresses into an array of strings. I know I could write a C program to do this, but I'd like to stay in Perl.
If you give a man a fish he will eat for a day.
If you teach a man to fish he will buy an ugly hat.
If you talk about fish to a starving man, you're a consultant.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.