I use a program that calls ImageMagick's command-line commands. These are supposed to run instantly -- perhaps 1 or 2 seconds. However, lately I've noticed a bunch of them got stuck.
I use monit to monitor the server and watch certain things when the memory goes overboard. What would be a good way to watch ImageMagick? I'd like to kill the processes if they've been alive for 1 minute. However, I don't want to do a blanket kill all convert
processes.
What do I do?
Thanks!
You can parse the output of
ps -ef
(orps -axf
on BSDish systems) to find processes with a start time (STIME
) greater thanX
, or you can useTIME
(CPU seconds used).Implementation of this solution is left as an exercise for the reader, it's relatively simple. Hints:
for line in top; do ... done
)grep
andawk
(orcut
) are your friendsSTIME
changes format depending on how long the process has been running.If we're talking within a 24 hour period you shouldn't have to worry about that, and you can kill any process that doesn't match the expected format for something started <24 hours ago.
echo "I want to kill $PID ($line)"
) before you let it really shoot processes in the head!Is it possible to modify the way ImageMagick is called? Setting limits with ulimit/limit before execing ImageMagick would allow you to set the CPU seconds and the kernel will take care of it for you.
http://www.cims.nyu.edu/cgi-comment/man.cgi?section=1&topic=limit
BASH FAQ entry #68: "How do I run a command, and have it abort (timeout) after N seconds?"