* updated lskat (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / misc / archive / killport.sh
blobd5b5dd1ffae994674420b1cdc9080c18a736de16
1 #!/bin/sh
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 #
6 # T2 SDE: misc/archive/killport.sh
7 # Copyright (C) 2004 - 2005 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
9 #
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 signal=15
19 returncode=0
21 for port ; do
22 xport="`printf '%04X' $port 2> /dev/null || echo ERROR`"
23 if [ "$xport" = "ERROR" ] ; then
24 echo "Not a valid port number: $port" >&2
25 returncode=$(($returncode + 1))
26 else
27 echo "Sending signal $signal to all processes connected" \
28 "to port $port:"
30 for proto in tcp udp ; do
31 echo -n " Inodes for `echo $proto | tr a-z A-Z`/$xport: "
32 inodes=`egrep "^ *[0-9]+: +[0-9A-F]+:$xport " /proc/net/$proto |
33 tr -s ' ' | cut -f11 -d' ' | tr '\n' ' '`
34 if [ "$inodes" ] ; then
35 echo "$inodes (getting pids)"
36 for inode in $inodes ; do
37 echo -n " PIDs for inode $inode: "
38 pids="`ls -l /proc/[0-9]*/fd/* 2> /dev/null | \
39 grep 'socket:\['$inode'\]' | tr -s ' ' |
40 cut -f9 -d' ' | cut -f3 -d/ | tr '\n' ' '`"
41 if [ "$pids" ] ; then
42 echo "$pids (sending signal)"
43 kill -$signal $pids
44 else
45 echo "None found."
47 done
48 else
49 echo "None found."
51 done
53 done
55 exit $returncode