On Thursday, May 30, 2002, at 08:04 , Kipp, James wrote:
> thanks. question: why the counter in your code example? I presume you mean the '$readIt++' - that is not really a counter, more just a boolean flag.... We set it to zero and once we see that the /$RightHeader/ we flip it on and get the next line of input. thus the next unless( $readIt or /$RightHeader/); should break on the $readIt being "TRUE" without needing to go to the other side of the 'or' ... this is an oldShellHackTrick - Have I seen the line I am looking for in some arbitrary data stream, hence I should move along.... If you KNOW for certain that once you start grovelling through what you expect and everything after the first failure to match your pattern is going to be 'extraneous' as in the case of there being more Gunge AFTER the 'Total' then one could use the 'last' command - flip the flag to Zero and see if we find another right header.... > <personally I would open up the source to prstat and do their > ps grovelling so that you archive only what you need> > > hmm..guess i should have scoured the man page before posting the question. > turns out one can print just the Total columns with 'prstat -t' which I presume means that it would gin up only the NPROC USERNAME SIZE RSS MEMORY TIME CPU 17 prago 1596M 394M 2.9% 0:48.54 11% 47 oracle 13G 12G 91% 38:17.25 4.1% 5 patrol 36M 23M 0.2% 10:53.17 0.2% 11 dbmsys 52M 20M 0.1% 0:00.53 0.1% 53 root 173M 113M 0.8% 5:32.40 0.1% Total: 208 processes, 875 lwps, load averages: 2.03, 2.04, 2.12 you will of course not that the code I offer you has no problem with that. so you could do the open(INPUTDATA, "prstat -t|") or die "silly critter not have prstat or it puked:$!\n"; or you might just go with my $pscmd='ps -ae -o user,rss,vsz,time'; open(INPUTDATA, "$pscmd|") or die "silly critter puked on ps cmd:$!\n"; and do your own direct grovelling of the data set: since your 'percentages' there are the ratio of RSS to VSZ... once one had converted that to and from page sizes - or not - if all you want is the percentages... > <DUCK> > but i learned some valuable info > <\DUCK> <QUACK/> I still say it would be fun to rip the prstat code apart and get your head around what really gets done in 'top' and/or any of it's variants.... moving right along here: I am a bit concerned by Sudarsan Raghavan most elegant offer: > # INPUTDATA is the filehandle through which you are getting the input > while (<INPUTDATA>) { > > chomp; > s/^\s+//; > next if (m/^$/ || (1 .. /^NPROC/)); > unless (/^Total/) { > # Assumes the line to stop searching for input starts with Total > my ($user, $mem, $cpu) = (split (/\s+/))[1, 4, 6]; > print "user = $user, mem = $mem, cpu = $cpu\n"; > } > as is it would generate user = USERNAME, mem = STATE, cpu = NICE user = prago, mem = cpu49, cpu = 0 user = oracle, mem = cpu46, cpu = 0 user = prago, mem = sleep, cpu = 0 user = oracle, mem = sleep, cpu = 0 user = oracle, mem = sleep, cpu = 0 user = prago, mem = sleep, cpu = 0 user = USERNAME, mem = MEMORY, cpu = CPU user = prago, mem = 2.9%, cpu = 11% user = oracle, mem = 91%, cpu = 4.1% user = patrol, mem = 0.2%, cpu = 0.2% user = dbmsys, mem = 0.1%, cpu = 0.1% user = root, mem = 0.8%, cpu = 0.1% so I fear his (1../^NPROC/) isn't doing quite what he was hoping that it would be doing.... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]