Re: howto kill x if x is running?
Organization: Thought Unlimited. Public service Unix since 1986. Of_Interest: With 27 years of service to the Unix community. On Sun, Sep 15, 2013 at 07:56:17AM +0100, Matthew Seaman wrote: > On 15/09/2013 07:20, Gary Kline wrote: > > > I've evidently had too many pain meds; this shelll script should > > be easy. 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? > > The classic answer to this is that you need to find the pid of your > 'xxx' process, and then kill it using that. Some combination of ps(1) > and grep(1) usually sufficed. > > However nowadays there's the very handy pkill(1): > > pkill -9 xxx > > Tying that in with the trigger based on system load: > > #!/bin/sh > > load=$(sysctl vm.loadavg | cut -d ' ' -f 3) > too_high=$(bc -e "$load > 0.15" < /dev/null) > > if [ $too_high = '1' ]; then > pkill -9 xxx > fi > > Note the use of bc(1) to compare floating point values -- the built-in > $((shell arithmetic)) or expr(1) only do integer arithmetic. > > One final point -- instead of killing the xxx process when the load gets > too high, you could simply renice(1) it to very low priority. Or even > better, use idprio(1). > > This won't actually affect the system load values much as 'system load' > is an average of the number of processes requesting a CPU time slice. > What it does do is mean that your 'xxx' process is always pretty much > the last process to get any CPU time -- so everything else should remain > responsive, and your xxx process will only run when the system is > otherwise idle. > > Cheers, > > Matthew thanks very much, gents. no, it wasnt my med; it was that I slept ttoo much:: Old age. "pkill -9 utility" works. the 0.15 or 0.10 were arbitrrary. the default load adverage should be even less since the box is just sitting here! ...well, it's replying to lookup, I suppose. tx again, gary > -- > Dr Matthew J Seaman MA, D.Phil. > > PGP: http://www.infracaninophile.co.uk/pgpkey > JID: matt...@infracaninophile.co.uk > -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix Twenty-seven years of service to the Unix community. http://www.thought.org/HOPE ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: howto kill x if x is running?
On 15/09/2013 07:20, Gary Kline wrote: > I've evidently had too many pain meds; this shelll script should > be easy. 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? The classic answer to this is that you need to find the pid of your 'xxx' process, and then kill it using that. Some combination of ps(1) and grep(1) usually sufficed. However nowadays there's the very handy pkill(1): pkill -9 xxx Tying that in with the trigger based on system load: #!/bin/sh load=$(sysctl vm.loadavg | cut -d ' ' -f 3) too_high=$(bc -e "$load > 0.15" < /dev/null) if [ $too_high = '1' ]; then pkill -9 xxx fi Note the use of bc(1) to compare floating point values -- the built-in $((shell arithmetic)) or expr(1) only do integer arithmetic. One final point -- instead of killing the xxx process when the load gets too high, you could simply renice(1) it to very low priority. Or even better, use idprio(1). This won't actually affect the system load values much as 'system load' is an average of the number of processes requesting a CPU time slice. What it does do is mean that your 'xxx' process is always pretty much the last process to get any CPU time -- so everything else should remain responsive, and your xxx process will only run when the system is otherwise idle. Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey JID: matt...@infracaninophile.co.uk signature.asc Description: OpenPGP digital signature
Re: howto kill x if x is running?
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, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
howto kill x if x is running?
Organization: Thought Unlimited. Public service Unix since 1986. Of_Interest: With 27 years of service to the Unix community. guys, I've evidently had too many pain meds; this shelll script should be easy. 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? gary -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix Twenty-seven years of service to the Unix community. http://www.thought.org/HOPE ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"