Created
May 9, 2019 20:16
-
-
Save jrelo/3af2cd727c4118b3d9875deaf1978e13 to your computer and use it in GitHub Desktop.
vzprocess: ps with CTID filtration for OpenVZ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
unless (scalar @ARGV == 1) { | |
die "Parameter needed, please pass ctid as parameter"; | |
} | |
my $ctid = $ARGV[0]; | |
sub get_ctid { | |
my $pid = shift; | |
open my $fl, "<", "/proc/$pid/status" or return 0; | |
while(<$fl>) { | |
if (/TaskUB:\s*(\d+)/i) { | |
return $1; | |
} | |
} | |
# it's host system | |
return 0; | |
} | |
my @all_processes = `ps aux`; | |
chomp @all_processes; | |
for my $process_raw (@all_processes) { | |
my (undef, $pid) = split /\s+/, $process_raw; | |
if (get_ctid($pid) == $ctid) { | |
print $process_raw, "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment