May 24, 2012
tom

Running bash script with php under lower priority or limit CPU

Question

I have a bash script which runs a set of php scripts. When it runs it takes an hour and pegs the CPU at 95-99%. This causes our lamp stack (mainly the apache process) problems and our website on the same server starts spitting out timeout or 500 errors.

How can I either:

  • Run the bash script and all associated tasks (php scripts which also call the PostgreSQL db) at a low priority so apache, php and db tasks for the web server are always prioritized, OR
  • Limit the CPU usage for the script and associated tasks to, e.g. 25% CPU

I’m not sure which is the better solution.

Asked by DaveR9

Answer

In addition to nice, looking at limiting CPU time, using ulimit -t (assuming you are on a *nix platform)

Answered by KM01

Related posts:

  1. running a bash script as root to change the date, when called by a php script
  2. running bash script as root with hardcoded password
  3. bash script to execute php file
  4. limit cpu ocupation for script
  5. Need help with executing and deleting remote bash script via a local bash script

Leave a comment