App-ppgrep
view release on metacpan or search on metacpan
lib/App/ppgrep.pm view on Meta::CPAN
# convert to numerical
if ($args{group} && @{$args{group}}) {
for (@{ $args{group} }) {
if (/\D/) {
my @ent = getgrnam($_);
$_ = @ent ? $ent[2] : -1;
}
}
}
if ($args{uid} && @{$args{uid}}) {
for (@{ $args{uid} }) {
if (/\D/) {
my @ent = getpwnam($_);
$_ = @ent ? $ent[2] : -1;
}
}
}
if ($args{euid} && @{$args{euid}}) {
for (@{ $args{euid} }) {
if (/\D/) {
my @ent = getpwnam($_);
$_ = @ent ? $ent[2] : -1;
}
}
}
my @res;
for my $p (@$ppids) {
my $match = 1;
MATCHING: {
if (defined $args{pattern}) {
if ($args{exact}) {
if ($args{full}) {
do { $match = 0; last MATCHING } unless $p->{cmdline} eq $args{pattern};
} else {
do { $match = 0; last MATCHING } unless $p->{name} eq $args{pattern};
}
} else {
if ($args{full}) {
do { $match = 0; last MATCHING } unless $p->{cmdline} =~ /$args{pattern}/;
} else {
do { $match = 0; last MATCHING } unless $p->{name} =~ /$args{pattern}/;
}
}
}
if ($args{pgroup} && @{$args{pgroup}}) {
my $found = 0;
for (@{ $args{pgroup} }) {
if ($_ == $p->{pgrp}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
if ($args{group} && @{$args{group}}) {
my $found = 0;
for (@{ $args{group} }) {
if ($_ == $p->{gid}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
if ($args{uid} && @{$args{uid}}) {
my $found = 0;
for (@{ $args{uid} }) {
if ($_ == $p->{uid}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
if ($args{euid} && @{$args{euid}}) {
my $found = 0;
for (@{ $args{euid} }) {
if ($_ == $p->{euid}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
if ($args{session} && @{$args{session}}) {
my $found = 0;
for (@{ $args{session} }) {
if ($_ == $p->{sess}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
if ($args{terminal} && @{$args{terminal}}) {
my $found = 0;
$p->{ttydev} =~ s!^/dev/!!;
for (@{ $args{terminal} }) {
if ($_ eq $p->{ttydev}) {
$found++; last;
}
}
do { $match = 0; last MATCHING } unless $found;
}
} # MATCHING
if ($args{inverse}) {
push @res, $p unless $match;
} else {
push @res, $p if $match;
}
}
my $res = "";
if ($args{count}) {
$res .= scalar(@res) . "\n";
} elsif ($args{list_full}) {
( run in 1.951 second using v1.01-cache-2.11-cpan-ceb78f64989 )