5
|
1 #!/usr/bin/perl |
|
2 # $Id: vz_ps.pl,v a19295214a68 2013/10/29 15:31:42 grin $ |
|
3 # (c) Petre Gervai, 2011-2013 |
|
4 # Released under CreativeCommons Attribution-ShareAlike v3.0 unported |
|
5 # CC-BY-SA-3.0-unp |
|
6 # |
|
7 # Show OpenVZ info using stock ps output instead of hacking it in |
|
8 # |
|
9 |
|
10 use warnings; |
|
11 use strict; |
|
12 use IO::File; |
|
13 |
|
14 my $ps = "/bin/ps"; |
|
15 |
|
16 my $f; |
|
17 |
|
18 if( $#ARGV == 0 ) { |
|
19 # use 'spawn ps' mode |
|
20 $f = new IO::File 'ps ' . join(' ', @ARGV) . " |" or die $!; |
|
21 |
|
22 } else { |
|
23 # get data on stdin |
|
24 $f = IO::Handle->new_from_fd( fileno(STDIN), 'r' ); |
|
25 } |
|
26 |
|
27 # get header |
|
28 my $hdr = <$f>; |
|
29 if( $hdr !~ /PID/ ) { |
|
30 print "Error: ps header doesn't contain PID, it's something I cannot accept. I'm going.\n"; |
|
31 exit 1; |
|
32 } |
|
33 |
|
34 my $pos; |
|
35 $hdr =~ s/^\s*(.+?)\s*$/$1/; # remove head/trail spc |
|
36 my @head = split /\s+/, $hdr; |
|
37 while( my ($i,$val) = each @head ) { |
|
38 if( $val=~ /^PID$/ ) { |
|
39 $pos = $i; |
|
40 last; |
|
41 } |
|
42 } |
|
43 |
|
44 use Data::Dumper; |
|
45 print Dumper( \@head, $pos ); |
|
46 die; |
|
47 |
|
48 while( <$f> ) { |
|
49 |
|
50 } |