title: How to list and kill threads/processes in Perl without using external command(s)?
body: <p>I need to <strong>kill</strong> some processes and threads <em>(if exist)</em> in <strong>Perl</strong> application, but I don't want to use external command(s) such as <code>ps</code>, <code>grep</code>, <code>awk</code>, <code>cut</code>, <code>uniq</code> or <code>kill</code>.</p>
  
  <p>My current code is:</p>
  
  <pre><code>      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&gt;&amp;1);
  </code></pre>
  
  <p>I am using VPS, so my memory is limited. The code above sometimes returns <code>undef</code>, as system cannot allocate memory for call of external command(s). I am looking for alternative solution without using external command(s).</p>