Skip to content

Instantly share code, notes, and snippets.

@Chaturaphut
Last active August 29, 2015 14:23
Show Gist options
  • Save Chaturaphut/027f0e13633c4004f4dc to your computer and use it in GitHub Desktop.
Save Chaturaphut/027f0e13633c4004f4dc to your computer and use it in GitHub Desktop.

Revisions

  1. @pavel-odintsov pavel-odintsov created this gist May 4, 2014.
    38 changes: 38 additions & 0 deletions gistfile1.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/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";
    }

    }