Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running some test on Amazon EC2 instances and we want to make the CPU always busy at above 80%.

What I have is a program main that needs to run in high priority and I want to launch another program, preferably some math C code or a bash script that loads the CPU to over 80%.

What programs are there to use for such a task, and how to make my program run with the highest priority.

PS: Running Fedora.

share|improve this question
up vote 2 down vote accepted

Occupying one CPU at 100% (minus overhead) is easy in the shell:

while true; do :; done

If you want to reduce the load, introduce sleeps.

i=0; while [ $i -ne 0 ] || sleep 0.001; do i=$(( (i+1) % 10000 )); done

Tune 10000 up or down to get the desired load.

The scheduling priority is set by nice. You'll need to be root to set a higher-than-default priority. Note that a negative niceness means high-priority (a positive niceness means be nice, i.e. low priority).

nice -20 sh -c 'while …'
share|improve this answer

With "nice" you can control the priority. For the highest priority (only available for root):

nice -n -20 yourprogram

And for the lowest:

nice -n 19 yourprogram

If you need control also the IO, use ionice. "man nice" and "man ionice" for the documentation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.