Reputation: 43703
I need to kill some processes and threads (if exist) in Perl application, but I don't want to use external command(s) such as ps
, grep
, awk
, cut
, uniq
or kill
.
My current code is:
my $appName = $0;
$appName =~ s/^.*\/([^\/]*)$/$1/;
$_ = qx(kill -9 `ps -eLao pid,command | grep '$appName\[ 0-9\]*\$' |
grep -v grep | awk '\$1 != $$' | cut -d' ' -f1 | uniq` 2>&1);
I am using VPS, so my memory is limited. The code above sometimes returns undef
, as system cannot allocate memory for call of external command(s). I am looking for alternative solution without using external command(s).
Upvotes: 2
Views: 619