Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Is there a better way ?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Is there a better way ?
Authored by: barrysharp on Jan 20, '02 10:36:42AM

...also it's always good practice to sanity check a value such as PID to see if it conforms. In this case the PID must be numeric. A /bin/sh function for doing this is as follows.

function isnumber
{
# Return TRUE status = 0 if argument contains ONLY digits
[[ $1 = +([0-9]) ]]
}

Thus one could script the following to sanity check the PID value

if ! isnumber `/bin/ps -axww | /usr/bin/grep '[/]APPNAME'| /usr/bin/awk '{print $1;exit}'`; then
echo PID is not numeric
else
echo PID is numeric
fi

This technique might be useful to make the "Nicer" feature more robust and maybe to avoid it doing stupid things. For example let's say that PID for some strange reason were to be the string "`/bin/rm *`". Now executing /usr/bin/renice $PID would be rather nasty. ;-)

Sanity check anything and everything that is done -- especially if it's done under the root account.

Regards... Barry Sharp



[ Reply to This | # ]