daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Proc::ProcessTable;
  6.  
  7. my $table = Proc::ProcessTable->new;
  8.  
  9. for my $process (@{$table->table}) {
  10.     # skip root processes
  11.     next if $process->uid == 0 or $process->gid == 0;
  12.  
  13.     # skip anything other than Passenger application processes
  14.     #next unless $process->fname eq 'ruby' and $process->cmndline =~ /\bRails\b/;
  15.  
  16.     # skip any using less than 1 GiB
  17.     next if $process->rss < 1_073_741_824;
  18.  
  19.     # document the slaughter
  20.     (my $cmd = $process->cmndline) =~ s/\s+\z//;
  21.     print "Killing process: pid=", $process->pid, " uid=", $process->uid, " rss=", $process->rss, " fname=", $process->fname, " cmndline=", $cmd, "\n";
  22.  
  23.     # try first to terminate process politely
  24.     kill 15, $process->pid;
  25.  
  26.     # wait a little, then kill ruthlessly if it's still around
  27.     sleep 5;
  28.     kill 9, $process->pid;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top