3 ################################################################
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 ################################################################
29 if ($ARGV[0] eq '-s' || $ARGV[0] eq '--signal') {
30 die("$ARGV[0]: argument required") unless @ARGV > 1;
36 if ($ARGV[0] eq '-v' || $ARGV[0] eq '--verbose') {
41 if ($ARGV[0] eq '-n') {
47 if ($ARGV[0] eq '-m' || $ARGV[0] eq '--message') {
48 die("$ARGV[0]: argument required") unless @ARGV > 1;
57 die("usage: killchroot [-s sig] <rootdir>") unless @ARGV == 1 && $ARGV[0] ne '';
59 chdir($dir) || die("$dir: $!\n");
61 $dir = readlink('/proc/self/cwd');
62 die("readlink /proc/self/cwd: $!\n") unless defined $dir;
68 opendir(D, "/proc") || die("/proc: $!\n");
69 for $pid (readdir(D)) {
70 next unless $pid =~ /^\d+$/;
71 $path = readlink("/proc/$pid/root");
72 next unless defined $path;
73 if ($path =~ /^\Q$dir\E(\/.*)?$/) {
76 $path = readlink("/proc/$pid/exe");
77 if ($path =~ /^\Q$dir\E(\/.*)?$/) {
83 my @pids = sort keys %pids;
86 print "$msg\n" if $msg ne '';
91 open(F, "</proc/$pid/cmdline");
93 sysread(F, $cmd, 128);
97 push @pidsv, "$pid($cmd)";
100 print "sending signal $sig to processes @pidsv\n";
102 print "sending signal $sig to process @pidsv\n";
107 kill CONT => @pids if $sig eq 9;