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'm running a piece of OCR software [with gui, etc] on OSX that watches a folder and OCRs PDFs that are put in there. Occasionally the process starts behaving poorly and consumes a huge amount of system memory and CPU, running indefinitely on a particular PDF.

  • I'd like to know how to monitor that process to kill it under such circumstances.
  • I'd also like to prevent it from bringing the system to a halt, e.g. by sandboxing somehow.
share|improve this question

You can sandbox an application on OS X with the built in sandbox(7) facility. See the man pages for sandbox(7), sandbox-exec(1) and sandboxd(8). This repository of sandbox scripts may also be useful.

OS X 10.7 (Lion) will bring more application sandboxing features, as well, but the details on Apple's site are light. I would assume it will be related to the above feature.

share|improve this answer

Plain ol' ps can help with this: we run a process that considers the number of seconds of CPU each process has consumed according to ps versus the elapsed wallclock time and alerts a sysadmin to have a look if the ratio is excessive; you could of course tie that to a kill for specific processes if you so choose.

share|improve this answer
Jeff - can you elaborate a touch. Which ps outputs are you using? What do you define as "excessive"? – Kyle Mar 21 '11 at 13:33
Well, the 'lstart' field will give you a proc's starting date and time in a parseable format, and the 'cputime' field will tell you the number of seconds of cpu time the process has consumed since it started. Convert current date/time and proc start date/time to epoch seconds, subtract to get the proc's total running seconds, then get the ratio of cpu seconds to running seconds. – Jeff Albert Mar 21 '11 at 16:38
What threshold is appropriate depends on your system and running processes; we alert by default when any process has used 300s of CPU time in 900s of wallclock, and then tune that figure based on a system's typical usage. – Jeff Albert Mar 21 '11 at 16:39
Thanks Jeff. Do you know of a way in which I can limit a process on OSX to consumption of only a certain amount of resources a priori? – Kyle Mar 23 '11 at 11:29
I don't know an easy way to specify a numeric value for cpu to wallclock time ratio; the 'nice' family of commands will allow you to specify a process's CPU scheduling priority, which might be what you're looking for (…) – Jeff Albert Mar 23 '11 at 16:35

to kill process you need to find its process number.

$ ps a| grep _process_name_

this results in list:


$ ps a|grep Safari
31755 s000  R+     0:00.00 grep Safari

now kill the process:

kill 31755

There are some switches for kill command, sometimes you need to use kill -kill _process number_

To get a full list of options use main kill

share|improve this answer

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.