1

I am utilising the very handy tool CPULimit to restrict the CPU usage of an import triggered in the cron of my Ubuntu server.

Successfully limiting the process is not a problem, I am also able to return the value back to no limit (100%) when the process ends, however when the import process terminates, I am left with CPULimit processes running. The list of CPULimit processes then gets appended to when the next cron job runs.

I can run a command like pkill -f cpulimit to remove the processes, however I am assuming there is a command that will terminate the limit, it just isn't documented.

To try help you understand here is a bit of a flow:

  1. Cron triggers import.
  2. Import script sets a cpulimit and points to > /dev/null: sudo -u {USER} cpulimit --pid {PID} --limit {LIMIT} > /dev/null &.
  3. A CPULimit process is added to the processes list when grep'ing ps aux | grep cpulimit.
  4. The import completes.
  5. The import script then returns the limit to 100%.
  6. A CPULimit process is added to the process list allowing 100% CPU.

~ This is what I thought would end the previous process, but it keeps the {LIMIT} processes running and the limit:100 process.

  1. The importer runs again.
  2. Two more CPULimit processes are added to the list in ps aux | grep cpulimit.

I can shell_exec(pkill -f cpulimit) which kills all the CPULimit processes other than the latest ones.

However, say I want to limit other processes and the timings don't work out perfectly, the limit on other restricted processes will also be killed.

Is there a way to initiate the cronjob, without freezing the importer when the CPULimit is applied (I got around this problem by sending it to > /dev/null), then when the importer ends, remove / delete / kill the limiter in this instance, as they currently just stack up?

** I am not requesting to kill the importer process if the limit is reached, I want to kill the CPULimit from the processes and remove the limit on the process it is limiting **

Doopz
  • 133
  • 1
  • 9

1 Answers1

1

This option is now included -z lazyness

cpulimit -P [/full/path/to/command] -mbzl 50

cpulimit [ Application ]

-P [ full path to script or command you want to limit ]

-b [ Run cpulimit in the background ]

-z [ lazyness stop cpulimit when there is no process left to limit ]

-l [ value between 0 - 400 for a 4 core cpu ]

-m [ also limit child processes ]