OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

  1. #!/bin/sh
  2. #
  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 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  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 ---
  17. signal=15
  18. returncode=0
  19. for port ; do
  20. xport="`printf '%04X' $port 2> /dev/null || echo ERROR`"
  21. if [ "$xport" = "ERROR" ] ; then
  22. echo "Not a valid port number: $port" >&2
  23. returncode=$(($returncode + 1))
  24. else
  25. echo "Sending signal $signal to all processes connected" \
  26. "to port $port:"
  27. for proto in tcp udp ; do
  28. echo -n " Inodes for `echo $proto | tr a-z A-Z`/$xport: "
  29. inodes=`egrep "^ *[0-9]+: +[0-9A-F]+:$xport " /proc/net/$proto |
  30. tr -s ' ' | cut -f11 -d' ' | tr '\n' ' '`
  31. if [ "$inodes" ] ; then
  32. echo "$inodes (getting pids)"
  33. for inode in $inodes ; do
  34. echo -n " PIDs for inode $inode: "
  35. pids="`ls -l /proc/[0-9]*/fd/* 2> /dev/null | \
  36. grep 'socket:\['$inode'\]' | tr -s ' ' |
  37. cut -f9 -d' ' | cut -f3 -d/ | tr '\n' ' '`"
  38. if [ "$pids" ] ; then
  39. echo "$pids (sending signal)"
  40. kill -$signal $pids
  41. else
  42. echo "None found."
  43. fi
  44. done
  45. else
  46. echo "None found."
  47. fi
  48. done
  49. fi
  50. done
  51. exit $returncode