Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[TOOL] Init Script to automagically renice processes at boot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Fri Sep 10, 2004 10:37 pm    Post subject: [TOOL] Init Script to automagically renice processes at boot Reply with quote

Hi.
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:
chmod u+x /etc/init.d/renice
rc-update add renice default


/etc/init.d/renice
Code:
#!/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
}


/etc/conf.d/nice
Code:
# 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


I hope these will be useful to someone.
:)
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
ExZombie
Apprentice
Apprentice


Joined: 29 May 2004
Posts: 164

PostPosted: Sat Sep 11, 2004 6:37 am    Post subject: Reply with quote

Hm, might be good, but I, for one, am already using this:
Code:

      *  app-admin/verynice
      Latest version available: 1.1
      Latest version installed: 1.1
      Size of downloaded files: 36 kB
      Homepage:    http://www.tam.cornell.edu/~sdh4/verynice/
      Description: A tool for dynamically adjusting the nice-level of processes
      License:     GPL-2


It can also kill runaway processes, if they are listed as such and start eating the CPU for no reason.
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Sat Sep 11, 2004 12:16 pm    Post subject: Reply with quote

didnt know that, thanks for pointing it out :)
mine is almost strcuted to be one-way for non-threading processes, i think.
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum