Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- mapcflip () {
- local xs=$1; shift
- local x
- for x in $(echo $xs | sed 's/,/ /g')
- do
- $(echo $@ | sed s/%/$x/)
- local ex=$?
- if test "${ex}" != 0
- then exit ${ex}
- fi
- done
- }
- lines2csv () {
- xargs echo | sed 's/ /,/g'
- }
- op_ls_root_pids() {
- for nixd_pid in $(pgrep nix-daemon)
- do
- echo "; builds of nix-daemon PID ${nixd_pid}"
- root_pids=`pgrep -P ${nixd_pid} | lines2csv`
- mapcflip "${root_pids}" ls -l /proc/%/cwd | grep -v 'root root' | cut -d' ' -f11- | cut -d- -f2-
- done
- }
- kill_stop() {
- kill -STOP $1
- }
- kill_cont() {
- kill -CONT $1
- }
- op_map() {
- local op="$1"; shift
- local pfx="$2"; shift
- for x in $*
- do
- ${op} ${x} "${pfx}"
- op_map ${op} "${pfx} " $(pgrep -P $x)
- done
- }
- op_tree() {
- local cut="$1"; shift
- local pfx="$1"; shift
- for x in $*
- do
- echo -n "${pfx}"
- ps -hp $x -o args | xargs echo | $cut
- op_tree "$cut" "${pfx} " $(pgrep -P $x)
- done
- }
- case "$1" in
- tree ) op_tree "cut -c-160" "" $(pgrep -n nix-daemon);;
- treeful ) op_tree "cat" "" $(pgrep -n nix-daemon);;
- suspend ) op_map kill_stop "" $(pgrep -n nix-daemon);;
- resume ) op_map kill_cont "" $(pgrep -n nix-daemon);;
- root | * ) op_ls_root_pids;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement