Created
August 27, 2009 08:10
-
-
Save pmakholm/176170 to your computer and use it in GitHub Desktop.
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 strict; | |
use warnings; | |
# Simple 'head -n N' implementation: | |
use Getopt::Long; | |
my $lines = 10; | |
GetOptions( | |
"lines|n=i" => \$lines, | |
); | |
while ($lines--) { | |
my $line = <>; | |
print $line; | |
} | |
# and now do some shooting... | |
# Find producers. For the example just care about people producing to STDOUT | |
no warnings 'uninitialized'; # readlink *will* return a lot of undefs | |
my $pipe = readlink "/proc/$$/fd/0"; | |
my @pids = grep { readlink("/proc/$_/fd/1") eq $pipe } map { s!^/proc/!!; $_ } glob "/proc/[0-9]*"; | |
print STDERR "Killing: ", join(", ", @pids), "\n" if $ENV{DEBUG}; | |
# Kill the producers | |
kill PIPE => @pids; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment