In my PHP web application, I am trying to limit the number of CPU / memory intensive processes that are running (e.g. ImageMagick 'convert' command). I have several krn jobs that execute various scripts that could potentially run too many instances of these processes with intensive processor / memory.
In an attempt to limit such processes, I first check to see if a certain number of processes are running on my system. Function:
function has_reached_process_limit($process, $limit) { $command = 'ps -eo comm | grep ' . $process; exec($command, $output, $return); if (count($output) > $limit) { return TRUE; } else { return FALSE; } }
So, I run something like this:
while (has_reached_process_limit('convert', 5) === TRUE) {
The problem is that when I control the resources of the OS (using the command "from above"), I see a lot of processes than I expect to work. Any ideas why?
source share