howto kill x if x is running?
Polytropon
freebsd at edvax.de
Sun Sep 15 06:47:23 UTC 2013
On Sat, 14 Sep 2013 23:20:46 -0700, Gary Kline wrote:
> say that I have a utility xxx running sometimes. xxx is
> soaking up a chunk of my load. I have to use top to find if
> xxx is running, then kill -9 to kill xxx and have a steady load of,
> say, between 0.10 and 0.15. what's the script that can do this?
Quick and dirty, needs adjustments. Repeat the following
(endless loop, depending on the shell you're using):
top -n | awk '/%/ { load=$11; sub("%", "", load); sub("\\.", "", load); if(load > 1000 && load < 1500) print $1 }' | xargs kill -9
The margin is coded in the conditional: 1000 means 10.00% WCPU
(load 0.10), 1500 means 15.00% WCPU (load 0.15). You will have
to set the "valid load" accordingly.
Done some minor testing, killed my media player (as expected).
I'm sure someone will present a much better, less dirtier
approach to accomplish the requested task. :-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list