cpulimit -e not catching all processes of that name
Hi!
I'm trying to limit pesky Google Chrome to around 25% CPU since it has a tendency to grind my PC to a halt.
I type 'cpulimit -e chrome -l 25', however it only monitors one process ID for CPU consumption, not all of name 'chrome'.
Many thanks, Rob.
Please, read documentation, or at least the HELP display when running just cpulimit with no flag.
As i know, Chrome uses a lot of child process to improve stability (they said that, not me).
-e is for put a binary name or path.
To include all the process children use -i flag.
Try cpulimit -v -i -e "chrome" -l 25
I installed cpulimit using brew and none of the 'extra' features work at all. I get Segmentation fault: 11 no matter what I try. The only thing that works is the -p PID option, which makes this no different from cputhrottle. The PID is for the main Google Chrome process, which apparently controls the many many Google Chrome Helper processes.
Options totally depends on the distro and the source of the file. I've checked mine (Debian 8 Jessie & cpulimit 2.1) and did worked.
Use it like:
for pid in pgrep chrome; do echo $pid && cpulimit -v -b -p "$pid" -l 50 ; done
Also, you can use this Python script https://gist.github.com/erm3nda/ccb8c2b333aa34070a10, wich is the same principle, but simple and direct. The usage is nearly the same, just:
for pid in `pgrep chrome`; do echo $pid && python cpulimit.py "$pid" ; done
and even with a couple of them, like:
pids=pgrep chrome && python cpulimit.py "$pids" but im not sure if this will handle an array or if does need to get a string like python cpulimit.py "1234 12355 12353" so feel free to explore.
I think you'll like more the simple Python than cpulimit. Is not the first time that I see compliants about some features that are only present on some particular (and uknown for me) distros.
On a Centos5 i tried it worked perfectly, but not on all. But, the Python one didn't fail me :-)
Best of luck.
Thanks for your swift reply. I didn't know about pgrep. It eliminates having to find the PID in the Activity Monitor, so I can automate it. I tried your first approach but it didn't work. I had to use pgrep -o "Google Chrome" to get the oldest, and hence, parent PID. It suffices to limit only the parent process, not the dozens of Google Chrome Helper processes, as your loop would do. So my final script is simply
cpulimit -l 0 -v -z -i -p $(pgrep -o "Google Chrome")
Works like a charm.
There's an important difference between processes and threads, im not sure about.
Also, -l 0 means limit 0% of the current usage, so will not touch it.
The -i is also not present in my current install. -z will terminate the running task of cpulimit when the process dies.
You can put it running forever and in background with cpulimit -l 0 -v -b -i -p $(pgrep -o "Google Chrome") as part of your current scripts.
Regards, glad it worked.
I'm using v0.2 installed by brew on OS X 10.8.5.
Usage: cpulimit [OPTIONS...] TARGET
OPTIONS
-l, --limit=N percentage of cpu allowed from 0 to 1600 (required)
-v, --verbose show control statistics
-z, --lazy exit if there is no target process, or if it dies
-i, --include-children limit also the children processes
-h, --help display this help and exit
TARGET must be exactly one of these:
-p, --pid=N pid of the process (implies -z)
-e, --exe=FILE name of the executable program file or path name
COMMAND [ARGS] run this command and limit it (implies -z)
-i limits child processes.
I'm pretty sure that all the Google Chrome Helper processes are child processes, not threads. They each have their own PID.

pgrep "Google Chrome"
29898
29897
29896
29895
29894
29893
29892
29891
29890
29889
29888
29887
29886
29885
29884
29883
29880
29879
29878
29877
29876
29875
29874
29873
29872
29871
29870
29869
29868
29867
29866
29865
29864
29863
29862
29861
29860
29858
29857
29856
29855
29854
29852
29851
29850
29849
29848
29847
29845
29843
29842
29840
29839
29826
29825
29824
29823
29822
29821
29820
29819
29818
29817
29816
29815
29814
29813
29811
29810
29809
29808
29807
29806
29805
29804
29803
29802
29800
29799
29798
29797
29795
29794
29790