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

So ImageMagick has the "convert" command which I use for my (Linux) web platform to deal with image resizing and such.

Sometimes this command gets "stuck", meaning it starts eating machine resources until the entire machine is unavailable. Logging in to the machine can take minutes when this happens.

SO, I'm looking for one of two solutions:

  1. Upon using this command - is there a way to determine just how much max resources it may use?

  2. Can I run a cron script that identifies these "stuck" processes and kill them? I.e. filter on CPU time, or CPU usage and kill when over a specific threshold.

I would probably prefer solution number 2, since solution number 1 could still yield several such processes that each is limited, and stuck, and together they would still eat up my resources.

I can't identify when and why this is happening, the system is slugish and stuck until I "killall convert", then all is well. This command is run thousands of times each hour so unless I would log each and every usage in some way, I can't say which one got stuck, unfortunately.

So, basically, a shell script that identifies, kills and logs when convert gets stuck.

Any ideas?

share|improve this question
Ah - what does ImageMagick support say to this? – TomTom Feb 16 '14 at 10:39
@TomTom: I haven't talked to them since it has been hard for me to find out under what circumstances this occurs. When the system is locked up, even doing a "top" or "ps" is time consuming and my first order of action is generally to "killall convert" to see if it helps, which it usually does. Not sure if I can see a log of what convert commands took time after I've killed them – Sandman Feb 16 '14 at 16:05
Smells like "swapping to death". – TomTom Feb 16 '14 at 16:06

Upon using this command - is there a way to determine just how much max resources it may use?

Just before invoking the convert command you can set a resource limit on the max CPU time the process can use, convert then will get killed automatically after exceeding the limit.

This will work depending upon how you invoke the command initially. The exec may be unnecessary.

ulimit -St 60
exec /usr/bin/convert $*
## if exec not present this gets executed after.
ulimit -St unlimited
share|improve this answer
Thanks - I am invoking the convert command from PHP, using the system() or shell_exec() command, would I use it like system("ulimit -St 60; convert ...; ulimit sSt unlimited") ? – Sandman Feb 16 '14 at 16:01

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.