No announcement yet.

How kill all users processes when they reach their memory limit?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How kill all users processes when they reach their memory limit?


    We have a customer who has some poorly written PHP files. They regularly hit their 2gb limit that is set by cloudlinux. (Which works perfectly, thanks!!!)

    I am wondering if there is any way to somehow "kill" all this users processes so that the memory can be released.

    (It usually takes a few hours for the memory to become used up, so the idea is that killing their processes would release the memory and then the usage cycle would start again. In the mean-time.. their website would at least work for a few hours before getting the error 500 due to no memory. They are working on a new website, but they need a few weeks of time.)

    Is this possible?
    (I understand this isnt a cloudlinux related issue. I am just hoping that maybe there is an expert here who might know what is the way to kill only this specific users processes that are consuming the memory. Somehow, cloudlinux is tracking the users memory usage, so there must be some way to know what are the processes used by the user, right?)


  • #2
    You should be able to add a script that PHP processes by that user if they had been there for longer then X minutes.


    • #3
      this can be done in several ways, most important question right now is what kind of php system u use ?
      mod_php/suphp/mod_fcgid or other ?

      im just guesing u dont use anykind of suid over php processes and its very hard to trace right procs with mod_php (which i assume u use cause with suexec u wouldnt have to ask this question)
      if thats correct then if switching to *suid* is impossible then u should write some little naughty module or track with some python/perl scripts proc or system table (but that would be very unefficient from dev point of view) cwd of process over sum up memory limiy values and kill pids


      • #4
        I ended up just keeping it very simple. I created a cron job that runs in the users account every 30 minutes:

        pkill php;
        It kills all processes owned by the user with "php" in the command.