Created
August 28, 2016 16:19
-
-
Save deepfire/35b07989d5a887880e01cf5e47a2a661 to your computer and use it in GitHub Desktop.
nix-builds: suspend/resume/observe the nix-build demon activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment