Process Limiting – How to Restrict CPU Time and Cycles for a Process

limitprocess

We have a script which runs on our web servers, triggered by customer action, which initiates a unix process to generate some cache files. Because this process acts upon files supplied by our customer, it sometimes misbehaves, running so long that the PHP process which spawns it times out or using so much CPU time that a sysadmin will kill it.

Is there any command which I could run which would limit the CPU time / runtime of the process? I am looking for a command like /usr/bin/time, where I could run that command and pass it the commandline I want it to run and limit.

Best Answer

In addition to Gilles answer there is cpulimit tool that does exactly what you want - including modifing in runtime. Additionally it can limit to only certain CPUs/Cores IIRC.

Related Question