Mercurial > openvz
view vz_ps.pl @ 5:464dea07deb8 default tip
Add vzps replacements.
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Wed, 07 May 2014 16:23:45 +0200 |
parents | |
children |
line wrap: on
line source
#!/usr/bin/perl # $Id: vz_ps.pl,v a19295214a68 2013/10/29 15:31:42 grin $ # (c) Petre Gervai, 2011-2013 # Released under CreativeCommons Attribution-ShareAlike v3.0 unported # CC-BY-SA-3.0-unp # # Show OpenVZ info using stock ps output instead of hacking it in # use warnings; use strict; use IO::File; my $ps = "/bin/ps"; my $f; if( $#ARGV == 0 ) { # use 'spawn ps' mode $f = new IO::File 'ps ' . join(' ', @ARGV) . " |" or die $!; } else { # get data on stdin $f = IO::Handle->new_from_fd( fileno(STDIN), 'r' ); } # get header my $hdr = <$f>; if( $hdr !~ /PID/ ) { print "Error: ps header doesn't contain PID, it's something I cannot accept. I'm going.\n"; exit 1; } my $pos; $hdr =~ s/^\s*(.+?)\s*$/$1/; # remove head/trail spc my @head = split /\s+/, $hdr; while( my ($i,$val) = each @head ) { if( $val=~ /^PID$/ ) { $pos = $i; last; } } use Data::Dumper; print Dumper( \@head, $pos ); die; while( <$f> ) { }