New libcgroup aware n.
[nethome.git] / bin / n
diff --git a/bin/n b/bin/n
new file mode 100755 (executable)
index 0000000..c4c8a8e
--- /dev/null
+++ b/bin/n
@@ -0,0 +1,25 @@
+#! /bin/sh
+if which ionice &>/dev/null;then
+       IONICE="ionice -c3"
+else
+       IONICE=""
+fi
+if [ "$1" = --n-class ];then
+  CGPARAM="$2"
+  shift 2
+else
+  CGPARAM="n"
+fi
+CGPARAM="-g cpu,memory,blkio:$CGPARAM"
+if cgexec $CGPARAM true 2>/dev/null;then
+       CGEXEC="cgexec $CGPARAM"
+       CGCLASSIFY="cgclassify $CGPARAM"
+else
+       CGEXEC=""
+       CGCLASSIFY="true"
+fi
+unset CGPARAM
+if [ -z "$*" ];then echo >&2 "No PID"
+elif [ "$1" = "-p" ];then renice >/dev/null +19 "$@";test -n "$IONICE" && $IONICE "$@";(shift;$CGCLASSIFY "$@")
+else exec nice -n19 $IONICE $CGEXEC "$@"
+fi