in reply to get system info using perl
like you I thought about making it more efficient by reading the file driectly. What I did, was find an assembly version of "cat", and did something like#!/usr/bin/perl use warnings; use strict; use IPC::Open3; $|=1; #my $pid=open3(\*IN,\*OUT,\*ERR,'/bin/bash'); my $pid=open3(\*IN,\*OUT,0,'/bin/bash'); # set \*ERR to 0 to send STDERR to STDOUT my $cmd = 'date'; #send cmd to bash print IN "$cmd\n"; my $result = <OUT>; print $result;
I never really accurately tested which one is fastest, but the assembly cat version made me feel fast. :-)sub refresh { my $pid = shift; #asmutils version of cat my @size = split "\n", `/home/zentara/perl5lib/cat /proc/$pid/stat +us`; #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 } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: get system info using perl
by saurabh.hirani (Beadle) on Feb 05, 2009 at 16:00 UTC |