I was involved in creating a metod to renice some processes which do not respond interactively (without using a scheduler).
So i created this script to perform this at boot time.
The script takes processes to be reniced from a convenient configuration file located at the standard gentoo conf dir /etc/conf.d; its syntax is pretty straight-foward.
Just edit these and then place it in your rc startup tree:
Code: Select all
chmod u+x /etc/init.d/renice
rc-update add renice defaultCode: Select all
#!/sbin/runscript
# renice
# license: GPL-2
# Author: Giovanni Ferri <giovanni@fonderiadigitale.it>
# This init script takes care of renicing programs specified in a
# table in /etc/conf.d/nice
# Refer to that file for help.
depend() {
need local
after xdm
}
start() {
local processlist active pid processname pli
local process=""
local value=""
local i=0
local c=0
local pids=0
let pli=${#processlist[*]}-1
conf=$(cat /etc/conf.d/nice 2>/dev/null|grep -v \#)
[ -z "${conf}" ] && exit 1
ebegin "Renicing programs"
for item in ${conf}
do
if ((c==0))
then
process=${item}
c=1
elif ((c==1))
then
value=${item}
case ${value} in
-[0-9]|-[0-9][0-9]) ;;
+[0-9]|+[0-9][0-9]) ;;
[0-9]|[0-9][0-9]) value="-${value}" ;;
*) unset value ;;
esac
let i=${i}+1
if [ -z "${process}" ] || [ -z "${value}" ]
then
ewarn "Error at line ${i} in /etc/conf.d/nice: ${item}"
else
active="$(pgrep -l -d, ${process})"
while [ -n "${active}" ]
do
string=${active%%,*}
#active=${active##${string},}
pid=${string%% *}
let pids=${pids}+1
processname=${string##* }
renice ${value} -p ${pid} >/dev/null
if [ ${pli} -eq 0 ] || ([ ${pli} -gt 0 ] && [ -n "${processlist[*]//*${processname}*}" ])
then
einfo " Reniced:\t[${value}]\t${processname}"
eend $?
processlist[${pli}]=${processname}
let pli=${pli}+1
fi
[ "${active}" == "${string}" ] && unset active || active=${active//${string},}
done
fi
c=0
fi
done
}
Code: Select all
# renicer configuration file
#
# Usage: a pair of values, the first for the exact
# name of a process, or a coherent pattern;
# the second one is the new unix nice value number,
# in the range -20/+19, where minor numbers mean
# faster system response;
# values without -/+ are considered to be meant -.
# Please consider that some programs, eg. OpenVPN
# have their own internal renicing mechanisms.
# Normally, filesystems and X11 should be reniced
# for a desktop machine.
# process value(-29 to +19)
kcryptd -18
xfslogd -15
xfsdatad -15
X -19

