From: Robert 'phaylon' Sedlacek Date: Tue, 1 May 2012 20:18:26 +0000 (+0000) Subject: FileHandles probe for lsof output X-Git-Tag: v0.001_001~138 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8ce5bf4989e416764f094a9e7d9d43b5e57d2451;p=scpubgit%2FSystem-Introspector.git FileHandles probe for lsof output --- diff --git a/lib/System/Introspector/FileHandles.pm b/lib/System/Introspector/FileHandles.pm new file mode 100644 index 0000000..2e3851d --- /dev/null +++ b/lib/System/Introspector/FileHandles.pm @@ -0,0 +1,27 @@ +package System::Introspector::FileHandles; +use Moo; + +sub gather { + my ($self) = @_; + my $pipe = $self->_open_lsof_pipe; + my @handles; + while (defined( my $line = <$pipe> )) { + chomp $line; + my @fields = split m{\0}, $line; + push @handles, { map { + m{^(.)(.*)$}; + ($1, $2); + } @fields }; + } + return \@handles; +} + +sub _open_lsof_pipe { + my ($self) = @_; + my $command = 'lsof -F0'; + open my $pipe, '-|', $command + or die "Unable to open pipe to '$command': $!\n"; + return $pipe; +} + +1;