Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created May 9, 2019 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrelo/3af2cd727c4118b3d9875deaf1978e13 to your computer and use it in GitHub Desktop.
Save jrelo/3af2cd727c4118b3d9875deaf1978e13 to your computer and use it in GitHub Desktop.
vzprocess: ps with CTID filtration for OpenVZ
#!/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