Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 3 down vote accepted

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!
share|improve this answer
That's interesting. Thanks! Will try this exercise. – Ramon Tayag Sep 21 '11 at 15:58

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.

share|improve this answer
I could, if I add a patch to the library I'm using. I've asked the guy in charge to look at this! – Ramon Tayag Sep 22 '11 at 15:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.