mirror of the now-defunct rocklinux.org
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.

62 lines
1.9 KiB

  1. #!/bin/sh
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/misc/archive/killport.sh
  11. # ROCK Linux is Copyright (C) 1998 - 2005 Clifford Wolf
  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; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. signal=15
  25. returncode=0
  26. for port ; do
  27. xport="`printf '%04X' $port 2> /dev/null || echo ERROR`"
  28. if [ "$xport" = "ERROR" ] ; then
  29. echo "Not a valid port number: $port" >&2
  30. returncode=$(($returncode + 1))
  31. else
  32. echo "Sending signal $signal to all processes connected" \
  33. "to port $port:"
  34. for proto in tcp udp ; do
  35. echo -n " Inodes for `echo $proto | tr a-z A-Z`/$xport: "
  36. inodes=`egrep "^ *[0-9]+: +[0-9A-F]+:$xport " /proc/net/$proto |
  37. tr -s ' ' | cut -f11 -d' ' | tr '\n' ' '`
  38. if [ "$inodes" ] ; then
  39. echo "$inodes (getting pids)"
  40. for inode in $inodes ; do
  41. echo -n " PIDs for inode $inode: "
  42. pids="`ls -l /proc/[0-9]*/fd/* 2> /dev/null | \
  43. grep 'socket:\['$inode'\]' | tr -s ' ' |
  44. cut -f9 -d' ' | cut -f3 -d/ | tr '\n' ' '`"
  45. if [ "$pids" ] ; then
  46. echo "$pids (sending signal)"
  47. kill -$signal $pids
  48. else
  49. echo "None found."
  50. fi
  51. done
  52. else
  53. echo "None found."
  54. fi
  55. done
  56. fi
  57. done
  58. exit $returncode