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.

56 lines
1.6 KiB

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