On Sun Jul 09 2000 at 12:53, "Malcor" wrote:

> Content-Type: text/html;
>       charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable

Please use text/plain and NOT text/html and quoted-UNprintable for
messages to mailing lists.

> Does anyone know how I would go about making a script that I could run =
> as a cron job that will check the system every 5 minutes for a process =
> using over x% of the cpu or ram?
> 
> It would be preferable if we could make it note the id in a file and on =
> the second check if the process were still running over X% then kill it.
> 
> Thanks for any help in advance=20
> 
> Scott Clifford

It is not difficult, a 5 minute job in itself.

- take the output of "ps aux | head" (or whatever)
- filter out the %CPU and %MEM fields to check for x% usage
- filter out the PID field out of the same line if > x%
- kill the process(es) if its PID has been previously saved
- save the PID if it isn't known
- remove the saved PID if the process was successfully killed

This would be very easily done with perl, but a shell script could
also do the job.

Set the cron job up in /etc/crontab for every 5 minutes.

I'd recommend against blindly killing processes like this, you never
know exactly what you'll end up killing.  Kill them, if possible,
with a -TRAP (-5) before resorting to a -TERM (-15) or a -KILL (-9).

My recommendation would be to renice those processes rather than
kill them outright (although it obviously depends on why you need to
do this in the first place).

Cheers
Tony

Reply via email to