Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

[TOOL] Init Script to automagically renice processes at boot

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
FonderiaDigitale
Veteran
Veteran
User avatar
Posts: 1710
Joined: Thu Nov 06, 2003 4:28 am
Location: Rome, Italy
Contact:
Contact FonderiaDigitale
Website

[TOOL] Init Script to automagically renice processes at boot

  • Quote

Post by FonderiaDigitale » Fri Sep 10, 2004 10:37 pm

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: Select all

chmod u+x /etc/init.d/renice
rc-update add renice default
/etc/init.d/renice

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

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
I hope these will be useful to someone.
:)
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Top
ExZombie
Apprentice
Apprentice
Posts: 170
Joined: Sat May 29, 2004 2:05 pm

  • Quote

Post by ExZombie » Sat Sep 11, 2004 6:37 am

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

Code: Select all

      *  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.
Top
FonderiaDigitale
Veteran
Veteran
User avatar
Posts: 1710
Joined: Thu Nov 06, 2003 4:28 am
Location: Rome, Italy
Contact:
Contact FonderiaDigitale
Website

  • Quote

Post by FonderiaDigitale » Sat Sep 11, 2004 12:16 pm

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 :)
Top
Post Reply

3 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy