Preventing a hog-process from eating up your CPU cycles.

Share your own howto's etc. Not for support questions!

Preventing a hog-process from eating up your CPU cycles.

Postby edbarx » 2014-05-28 10:03

cpulimit is a simple cpu usage limiter for processes. Some programs eat far too many CPU cycles for what they do. This tool comes in handy in such a situation.

For multicore processors the allowable percentage is 100n, where n is the number of processor cores. So, if you own a quad-core processor, it would mean the allowable percentage is 400%.

The following assumes a single core processor:
Suppose process cpu_gobbler is eating 100% of your CPU cycles (and you cannot figure out why it should do so). You can 'educate' cpu_gobbler to behave by using cpulimit in this way, obviously, after starting cpu_gobbler.

After starting cpu_gobbler use top to find its process ID. Let us assume the latter is 4112. Then, issue this simple command:
Code: Select all
cpulimit -p 4112 -l 10 -z


Where:
  1. -p precedes the process ID
  2. -l precedes the percentage of CPU cycles to be allowed (el not one!)
  3. -z tells cpulimit to terminate as soon as cpu_gobbler dies/terminates

Instead of the proces ID you can use the executable's file name. This is achieved using the switch:
Code: Select all
 --exe=cpu_gobbler


For further details, if any, consult the manpage as it is one of the easiest to understand.

P.S.:
I am using cpulimit on MS Skype :P :mrgreen:.
Last edited by edbarx on 2014-05-29 16:14, edited 3 times in total.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5394
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: Preventing a hog-process from eating up your CPU cycles.

Postby argorain » 2014-05-28 13:39

Great tip, thanks.
Vojtech "Rain" Vladyka
User avatar
argorain
 
Posts: 58
Joined: 2014-04-15 05:31
Location: CR

Re: Preventing a hog-process from eating up your CPU cycles.

Postby edbarx » 2014-05-31 06:58

For those interested, I am using cpulimit with -l 17 for Skype on an Intel T4400 2.2GHz CPU! Obviously, I have video disabled. This means, I am running Skype with only 8.5% of my computer's power. 8)
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5394
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable