Created
November 12, 2019 04:41
-
-
Save equwal/4bb9bfbb3c207d77fd04a809414358d2 to your computer and use it in GitHub Desktop.
Murder processes with a pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use warnings; | |
| use strict; | |
| my $pattern; | |
| my $murder; | |
| if($#ARGV > 0) { | |
| $murder = 1; | |
| $pattern = $ARGV[1]; | |
| print "Murdering:\n"; | |
| } else{ | |
| $pattern = $ARGV[0]; | |
| $murder = 0; | |
| print "Stalking. Use murder -k PAT to murder.\n"; | |
| } | |
| my $ps = `ps -eo pid,comm --no-headers`; | |
| my @ps = split "\n", $ps; | |
| for(@ps) { | |
| if(/^\s*(\d+?)\s(.*$pattern.*)$/) { | |
| if($murder) { | |
| print "\t$1 $2\n"; | |
| `kill $1`; | |
| } else { | |
| print "$1 $2\n"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment