New libcgroup aware n.
authorJan Kratochvil <jan.kratochvil@redhat.com>
Sun, 27 Feb 2011 10:01:30 +0000 (11:01 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Sun, 27 Feb 2011 10:01:30 +0000 (11:01 +0100)
bin/n [new file with mode: 0755]

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