0

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.

Frozen processes

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!

voretaq7
  • 79,879
  • 17
  • 130
  • 214
Ramon Tayag
  • 479
  • 2
  • 7
  • 17

3 Answers3

3

You can parse the output of ps -ef (or ps -axf on BSDish systems) to find processes with a start time (STIME) greater than X, or you can use TIME (CPU seconds used).


Implementation of this solution is left as an exercise for the reader, it's relatively simple. Hints:

  • You can do it with a shell script (for line in top; do ... done)
  • grep and awk (or cut) are your friends
  • STIME 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.
  • Test your script first (echo "I want to kill $PID ($line)") before you let it really shoot processes in the head!
voretaq7
  • 79,879
  • 17
  • 130
  • 214
0

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

polynomial
  • 4,016
  • 14
  • 24
  • I could, if I add a patch to the [library I'm using](https://github.com/markevans/dragonfly). I've asked the guy in charge to look at this! – Ramon Tayag Sep 22 '11 at 15:15