Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. mapcflip () {
  4. local xs=$1; shift
  5. local x
  6.  
  7. for x in $(echo $xs | sed 's/,/ /g')
  8. do
  9. $(echo $@ | sed s/%/$x/)
  10.  
  11. local ex=$?
  12. if test "${ex}" != 0
  13. then exit ${ex}
  14. fi
  15. done
  16. }
  17.  
  18. lines2csv () {
  19. xargs echo | sed 's/ /,/g'
  20. }
  21.  
  22. op_ls_root_pids() {
  23. for nixd_pid in $(pgrep nix-daemon)
  24. do
  25. echo "; builds of nix-daemon PID ${nixd_pid}"
  26. root_pids=`pgrep -P ${nixd_pid} | lines2csv`
  27. mapcflip "${root_pids}" ls -l /proc/%/cwd | grep -v 'root root' | cut -d' ' -f11- | cut -d- -f2-
  28. done
  29. }
  30.  
  31. kill_stop() {
  32. kill -STOP $1
  33. }
  34. kill_cont() {
  35. kill -CONT $1
  36. }
  37.  
  38. op_map() {
  39. local op="$1"; shift
  40. local pfx="$2"; shift
  41. for x in $*
  42. do
  43. ${op} ${x} "${pfx}"
  44. op_map ${op} "${pfx} " $(pgrep -P $x)
  45. done
  46. }
  47.  
  48. op_tree() {
  49. local cut="$1"; shift
  50. local pfx="$1"; shift
  51. for x in $*
  52. do
  53. echo -n "${pfx}"
  54. ps -hp $x -o args | xargs echo | $cut
  55. op_tree "$cut" "${pfx} " $(pgrep -P $x)
  56. done
  57. }
  58.  
  59. case "$1" in
  60. tree ) op_tree "cut -c-160" "" $(pgrep -n nix-daemon);;
  61. treeful ) op_tree "cat" "" $(pgrep -n nix-daemon);;
  62. suspend ) op_map kill_stop "" $(pgrep -n nix-daemon);;
  63. resume ) op_map kill_cont "" $(pgrep -n nix-daemon);;
  64. root | * ) op_ls_root_pids;;
  65. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement