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 } } }
In reply to Re: get system info using perl
by zentara
in thread get system info using perl
by saurabh.hirani
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |