list-all-graphene.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. ID=`id -u`
  3. PGIDS=`ps -a -o pgid,command | tail -n +2 | \
  4. awk "{ if (\\\$2 ~ /\\/pal\$/ ) print \\\$1 }" | uniq`
  5. NONE=1
  6. for PGID in $PGIDS
  7. do
  8. NONE=0
  9. ps -p $PGID -o pid,args 2> /dev/null | tail -n +2
  10. done
  11. if [ "$NONE" = "1" ]; then
  12. echo "no graphene instance"
  13. exit 0
  14. fi
  15. echo -n "choose intance(s): "
  16. read SELECT_PGIDS
  17. DO_KILL=0
  18. for CMD in $SELECT_PGIDS
  19. do
  20. if [ "$CMD" = "kill" ]; then
  21. SELECT_PGIDS=${SELECT_PGIDS:4}
  22. DO_KILL=1
  23. fi
  24. break
  25. done
  26. do_list()
  27. {
  28. PGID=$1
  29. echo "instance $PGID:"
  30. PIDS=`ps -a -o pgid,pid --sort=start_time 2> /dev/null | tail -n +2 | \
  31. awk "{ if (\\\$1 == $PGID) print \\\$2 }"`
  32. CNT=1
  33. for PID in $PIDS
  34. do
  35. STAT=`ps -a -p $PID -o stat | tail -n +2`
  36. if [[ $STAT == Z* ]]; then
  37. printf " %3d: process %5d (DEAD):" $CNT $PID
  38. else
  39. printf " %3d: process %5d :" $CNT $PID
  40. fi
  41. for TASK in /proc/$PID/task/*
  42. do
  43. printf " %5d" ${TASK##*/}
  44. done
  45. echo
  46. CNT=`expr $CNT + 1`
  47. done
  48. }
  49. do_kill()
  50. {
  51. PGID=$1
  52. PIDS=`ps -a -o pgid,pid 2> /dev/null | tail -n +2 | \
  53. awk "{ if (\\\$1 == $PGID) print \\\$2 }"`
  54. kill -9 $PGID $PIDS
  55. }
  56. NONE=1
  57. for PGID in $SELECT_PGIDS
  58. do
  59. if [ "$DO_KILL" = "1" ]; then
  60. do_kill $PGID
  61. else
  62. do_list $PGID
  63. fi
  64. NONE=0
  65. done
  66. if [ "$NONE" = "1" ]; then
  67. for PGID in $PGIDS
  68. do
  69. if [ "$DO_KILL" = "1" ]; then
  70. do_kill $PGID
  71. else
  72. do_list $PGID
  73. fi
  74. done
  75. fi