5 # GPL - jan.mette@berlin.de
9 #############################################################################
11 #############################################################################
14 source /etc
/conf.d
/ioreniced
16 # initialize pidlist for garbage collection
17 if [ "${BEHAVIOR}" = "smart" ]
23 rm -rf ${LOG_FILE} &>/dev
/null
26 trap 'echo "source /etc/conf.d/ioreniced' 1
27 trap 'rm -f /var/run/ioreniced.run; exit' 0
28 trap 'rm -f /var/run/ioreniced.run; exit' 3
29 trap 'rm -f /var/run/ioreniced.pid; exit' 15
32 #############################################################################
34 #############################################################################
39 DATE
=`date '+%b%e %H:%M:%S'`
41 if [ "${BEHAVIOR}" = "smart" ]
44 # create logfile if it doesnt exist
45 if [ "${ENABLE_LOGGING}" = "yes" ]
47 if [ ! -e "${LOG_FILE}" ]
51 echo "-------------------------------------">>${LOG_FILE}
52 echo " ioReniceD Logfile ">>${LOG_FILE}
53 echo "-------------------------------------">>${LOG_FILE}
59 if [ "${ENABLE_LOGGING}" = "yes" ]
61 echo "${DATE} >>>> Running Garbage Collector">>${LOG_FILE}
64 for pid2
in ${IONICED_LIST}
66 check_running
=`ps -A | grep ${pid2}`
68 if [ -z "$check_running" ]
70 if [ "${ENABLE_LOGGING}" = "yes" ]
72 echo "${DATE} >> PID ${pid2} not running anymore, removing from process list">>${LOG_FILE}
75 IONICED_LIST=`echo ${IONICED_LIST} | sed "s
/${pid2}//g
"`
77 if [ "${ENABLE_LOGGING}" = "yes" ]
79 echo "${DATE} >> PID LIST: ${IONICED_LIST}">>${LOG_FILE}
84 # walk through the list of processes we want to ionice
85 if [ "${ENABLE_LOGGING}" = "yes" ]
87 echo "${DATE} >>>> Ionicing Processes">>${LOG_FILE}
90 for item
in `echo ${IONICE_ME[*]}`
92 # filter process list and remove stuff we dont want to ionice. just to be sure we dont hit anything cruicial ;) needs to be simplified
93 for pid
in `ps -A | grep "${item}" | grep -e "acpi" -e "work_on_cpu" -e "startkde" -v | sed "s/[^ 0-9].*//g"`
95 # check if we already have ionized this process
96 PID_TMP
=`echo ${IONICED_LIST} | grep -e "${pid}"`
98 if [ -z "${PID_TMP}" ]
100 if [ "${ENABLE_LOGGING}" = "yes" ]
102 echo "${DATE} >> ionicing new process ${item} (PID ${pid}) with PRIO ${IONICE_PRIO}">>${LOG_FILE}
105 /usr/bin/ionice -c${IONICE_PRIO} -p${pid} &>/dev/null
107 IONICED_LIST="${IONICED_LIST} ${pid}"
109 if [ "${ENABLE_LOGGING}" = "yes" ]
111 echo "${DATE} >> process ${item} (PID ${pid}) already ioniced with PRIO ${IONICE_PRIO}, skipping">>${LOG_FILE}
117 # delete logfile it if its size is over 1mib
118 if [ -e "${LOG_FILE}" ]
120 LOGSIZE
=$
(stat
-c%s
"${LOG_FILE}")
122 if [ "${LOGSIZE}" -gt 1048576 ]
129 if [ "${ENABLE_LOGGING}" = "yes" ]
131 echo "${DATE} >>>> ---------------------------------MARK">>${LOG_FILE}
135 if [ "${BEHAVIOR}" = "brute" ]
137 # create logfile if it doesnt exist
138 if [ "${ENABLE_LOGGING}" = "yes" ]
140 if [ ! -e "${LOG_FILE}" ]
143 echo " ">>${LOG_FILE}
144 echo "-------------------------------------">>${LOG_FILE}
145 echo " ioReniceD Logfile ">>${LOG_FILE}
146 echo "-------------------------------------">>${LOG_FILE}
147 echo " ">>${LOG_FILE}
151 # walk through the list of processes we want to ionice
152 if [ "${ENABLE_LOGGING}" = "yes" ]
154 echo "${DATE} >>>> Ionicing Processes">>${LOG_FILE}
157 for item
in `echo ${IONICE_ME[*]}`
159 # filter process list and remove stuff we dont want to ionice. just to be sure we dont hit anything cruicial ;) needs to be simplified
160 for pid
in `ps -A | grep "${item}" | grep -e "acpi" -e "work_on_cpu" -e "startkde" -v | sed "s/[^ 0-9].*//g"`
162 if [ "${ENABLE_LOGGING}" = "yes" ]
164 echo "${DATE} >> ionicing process ${item} (PID ${pid}) with PRIO ${IONICE_PRIO}">>${LOG_FILE}
166 /usr/bin/ionice -c${IONICE_PRIO} -p${pid} &>/dev/null
170 # delete logfile it if its size is over 1mib
171 if [ -e "${LOG_FILE}" ]
173 LOGSIZE=$(stat -c%s "${LOG_FILE}")
175 if [ "${LOGSIZE}" -gt 1048576 ]
182 if [ "${ENABLE_LOGGING}" = "yes" ]
184 echo "${DATE} >>>> ---------------------------------MARK">>${LOG_FILE}
189 sleep ${POLLING_INTERVAL}